On 26.12.2019 23:42, Marco van de Voort wrote:
Op 12/26/2019 om 9:12 PM schreef Ondrej Pokorny:

In Delphi TEncoding.ANSI and TEncoding.Default are actually different. See: http://docwiki.embarcadero.com/Libraries/Rio/en/System.SysUtils.TEncoding.Default http://docwiki.embarcadero.com/Libraries/Rio/en/System.SysUtils.TEncoding.ANSI

On Windows, they are equal but on POSIX they are different: TEncoding.Default is UTF-8 but TEncoding.ANSI is the code page from CFLocaleGetIdentifier.

And in FPC it is exactly the same,

No, it is not. In FPC:
class function TEncoding.GetDefault: TEncoding;
begin
  Result := GetANSI;
end;

For the meaning of TEncoding.Default and TEncoding.ANSI in Delphi see the docs above.


BUT Lazarus overrides default with UTF8 on Windows.

Yes, it does it since r61976 - so only recently. And it is a very questionable commit because
a) is not Delphi compatible
b) breaks OS-ANSI calls
c) breaks ANSI FPC code

It must either be reverted or we need some high-level method to get the OS-ANSI codepage without this override.


As you can see that is NOT compatible with Delphi above.
Yes, and I am against r61976 - but because r61976 overrides TEncoding.ANSI to UTF-8 on Windows. IMO TEncoding.Default should be UTF-8 in Lazarus even on Windows (whereas TEncoding.ANSI should stay OS-ANSI) - I try to explain again why this actually fits very well into the Delphi/FPC encoding concept. I will now talk only about Windows for simplicity (because the ANSI concept is most important on Windows):

Delphi doesn't know the DefaultSystemEncoding concept that FPC has. The default AnsiString encoding in Delphi is always OS-ANSI (CP_ACP). Therefore it makes perfect sense to have TEncoding.Default to point to the default AnsiString encoding that is OS-ANSI encoding in Delphi.

FPC, on the contrary, overrides the CP_ACP value with DefaultSystemEncoding. So the default AnsiString encoding is not OS-ANSI but DefaultSystemEncoding. Therefore, again, it makes perfect sense to have TEncoding.Default to point to the default AnsiString encoding that is DefaultSystemEncoding in FPC.

Onrej
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to