[fpc-devel] Delphi incompatible encoding
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Dec 2 04:05:59 CET 2014
Jonas Maebe schrieb:
>
> Hans-Peter Diettrich wrote on ma, 01 dec 2014:
> To get behaviour that is compatible with Delphi2009+, compile with
> -Mdelphiunicode or {$modeswitch delphiunicode}.
The compiler option (-M) works, but the $modeswitch is not accepted by
the compiler (2.7.1): Illegal compiler switch "DELPHIUNICODE". The same
for {$mode ObjPas} - what else did I miss?
When I use Lazarus and set the compiler to the new 2.7.1, the modeswitch
does not cause an error.
> This particular
> difference is also documented in
> http://wiki.freepascal.org/FPC_Unicode_support#String_constants (search
> for delphiunicode or systemcodepage)
Thanks, that explains at least the FPC handling of literals.
But where can I find information about all the differences caused by
above compiler option/modeswitch? Does it affect implicit AnsiString
encoding conversions?
BTW it's nice that FPC console Write/Ln (mostly) converts AnsiStrings to
the console codepage, while Delphi (XE) doesn't convert :-)
But I found a somewhat strange result with generic String variables,
tested with:
var A: AnsiString; S: String;
begin
S := ' äöü';
A := S;
//S := A; //changes nothing
WriteLn('A CP: ',StringCodePage(A), A); //always shows ' äöü'
WriteLn('S CP: ',StringCodePage(S), S); //letters differ
end.
When String is UnicodeString (DelphiUnicode), the output is correctly
converted for both strings (CP 1200,1252). But when String is not
UnicodeString, AnsiString and String should be the same type, no? The
console however shows different letters for the generic String and
AnsiString variable (both CP 1252). The output doesn't change when A is
assigned back to S. How that?
When A and S are echanged:
A := ' äöü';
S := A;
//A := S; //CP changes
the encoding of A is shown as zero. Now it makes a difference when S is
assigned back to A, but only the codepage of A then also is shown as
1252, while the letters still differ. Obviously String is not equivalent
to AnsiString now, and string literals should be assigned to AnsiString
variables only, not to String variables?
Very confused
DoDi
More information about the fpc-devel
mailing list