this is working with out any other command for me on win
{$mode objfpc}{$H+}
WriteLn(UTF8ToSys('α'));
It does not work here for two reasons:
1-On my system UTF8ToSys('α') will not produce the correct value, because my system has a different code page than yours.
2-I'm using FPC 2.7.1 with FPC_HAS_CPSTRING defined. This means that if the code page of a string is different than the Output record's code page then a conversion happens.
The compiler translates WriteLn to a few calls to fpc_Write_Text_***.
Compare for instance
fpc_Write_Text_AnsiStr on the trunk:
Procedure fpc_Write_Text_AnsiStr (...
...
{$if defined(FPC_HAS_CPSTRING) and defined(FPC_HAS_FEATURE_ANSISTRINGS)}
if slen > 0 then
if TextRec(f).CodePage<>TranslatePlaceholderCP(StringCodePage(S)) then
begin
a:=fpc_AnsiStr_To_AnsiStr(S,TextRec(f).CodePage); //<---------This conversion
fpc_WriteBuffer(f,PAnsiChar(a)^,Length(a));
with
fpc_Write_Text_AnsiStr in 2.6.4:
Procedure fpc_Write_Text_AnsiStr (...
...
if slen > 0 then
fpc_WriteBuffer(f,PChar(S)^,SLen);
Using DOS Greek code page (737), I can type that letter as a single character if I know its correct value in this code page (α is #$98):
const
CP_DosGreek = 737;
...
if SetConsoleOutputCP(CP_DosGreek) then
WriteLn(#$98);//Utf8TpSys('α')
Notice that SetConsoleOutputCP will not change the code page in the Output record. Maybe setdefaultcodepage mentioned by Marcov does the trick, but I don't know where to find it.
I can also write that letter using CP_UTF8:
PreviousValue := GetConsoleOutputCP;
//Using UTF8
WriteLn('Using CP_UTF8');
if not SetConsoleOutputCP(CP_UTF8) then
begin
WriteLn('SetConsoleOutputCP(CP_UTF8) Failed!');
exit;
end;
S := 'α';
{$ifdef FPC_HAS_CPSTRING} //<--- Based on your compiler
WriteLn('Check codepages: ','GetTextCodePage(Output): ', GetTextCodePage(Output),', StringCodePage(s): ', StringCodePage(s));
WriteLn();
WriteLn('This may not work: ',s);
if GetTextCodePage(Output)<>StringCodePage(s) then
begin
WriteLn();
WriteLn('Changing Output codepage from ',GetTextCodePage(Output),' to ',StringCodePage(s));
SetTextCodePage(Output, StringCodePage(s));
end;
{$endif FPC_HAS_CPSTRING}
WriteLn('This works: ',s);//Now it works!
SetConsoleOutputCP(PreviousValue);