[fpc-devel] Delphi incompatible encoding

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Dec 1 14:37:49 CET 2014


Hans-Peter Diettrich wrote on ma, 01 dec 2014:

> Now I could compile FPC 2.7.1 and perform some tests :-)
> Unfortunately I couldn't submit an bug report, so it comes here:
>
> When compiled with Delphi XE, the code below shows 1252 (my  
> DefaultSystemCodePage) for all strings, be empty or non-empty.
>
> Compiled with FPC 2.7.1, the StringCodePage(r) is reported as zero  
> after the first assignment (r := s;).
> This is incompatible with Delphi :-(
>
> program rawtest;
> var
>   s: AnsiString; //UTF8String;
>   r: RawByteString;
> begin
>   s := 'abc';
>   r := s;
>   WriteLn('s CP: ',StringCodePage(s)); //1252
>   WriteLn('r CP: ',StringCodePage(r)); //XE: 1252, FPC: 0
>   s := r;
>   WriteLn('s CP: ',StringCodePage(s)); //XE: 1252, FPC: 0
> end.
>
> This difference may be due to an error in StringCodePage, more  
> probably in RawByteString handling in general.

To get behaviour that is compatible with Delphi2009+, compile with  
-Mdelphiunicode or {$modeswitch delphiunicode}. This particular  
difference is also documented in  
http://wiki.freepascal.org/FPC_Unicode_support#String_constants  
(search for delphiunicode or systemcodepage)


Jonas



More information about the fpc-devel mailing list