I disagree, too.
I was saying, in other words, that this might be a case in which FPC will not get the right encoding automatically. With "automatically" I mean: Just declare a variable as "string", nothing else. You are just confirming my statement because you add extra code specifying the codepage. Your code does not even compile with fpc 2.6.4 (Laz 1.4.4), therefore, it does not belong to section"Old code", it belongs to "New code" and is a third option how to handle the encoding correctly today, thanks for bringing this up.
OK, I will not disagree, but I am not sure why you think it is FPC problem. FPC trusts DefaultSystemCodePage value to be correct, while LCL changes it to UTF8, that's one. Two, when you declare a variable as "string" that means, for LCL, it is UTF8 encoding. Assigning non-UTF8 value, like #$e4, is an error.
Actually having a procedure like
SetString that does not take code page as one of the parameters does not make sense, as well. In fact FPC has a
compiler procedure named
fpc_setstring_ansistr_pansichar could be exposed as in:
procedure SetStringCP(out S : RawByteString; Buf : PAnsiChar; Len : SizeInt; cp: TSystemCodePage);external name 'fpc_setstring_ansistr_pansichar';
Then simply:
SetStringCp(RawByteString(s), PansiChar(@a[0]), Length(a), 1252);
And to satisfy LCL UTF8 requirement:
ShowMessage(UTF8String(s));
or any other method.
By the way, IMHO, WinCPToUTF8 is the worst to use.