procedure p;
var
f:TextFile;
oemst:OemString;///declared as OemString = Type AnsiString(CP_OEMCP);
begin
AssignFile(f,fileName);
reset(f);
read(f,oemSt);
ShowMessage(oemst);
end;
In order to see within the show message the oemst in the proper encoding, one needs to declare:
setcodepage(oemst,862,false);
How is it possible to read from an oem file, and make sure the compiler show it correctly in oem encoding?
update: Working with Oem is a MUst, as I don't specify this old interface. working with readln assign file is part of the old code, and I rather have a solution using the old methods as it requires less work and testing.
In D2009 and up you are usually better off not using the old Pascal file methods like assignfile, read(ln) and write(ln) as they do not support Unicode. And everybody will advice you to use streams instead. In this case you may actually be better of using the old way because it doesn't understand Unicode.
While you are setting the code page correctly, what I think you need to do to get this to work for you, is set the console's code page using SetConsoleCP
. That is a Windows API call which is declared in the Windows unit.