[fpc-devel] TEncoding.Default and default encoding for TStrings.LoadFrom*()

Marco van de Voort fpc at pascalprogramming.org
Thu Dec 26 23:42:21 CET 2019


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, BUT Lazarus overrides default with 
UTF8 on Windows. As you can see that is NOT compatible with Delphi above.

Worse, since the startup encoding is the encoding to communicate with 
the OS, as soon as

> Read the .NET docs about Encoding.Default:
> https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding.default?redirectedfrom=MSDN&view=netframework-4.8#System_Text_Encoding_Default 
>
> on .NET Framework it is ANSI but on .NET Core it is UTF-8 even on 

Yes, totally irrelevant. On Windows ansi means something like 
Windows-1252 and  -A apis, and the only unicode api is -W and UTF8. .NET 
is as relevant as Linux in this matter; other application API.

> With all the information from the docs, I am more and more convinced 
> that TEncoding.SystemEncoding is superfluous and TEncoding.Default 
> should take over its meaning: TEncoding.Default should reflect changes 
> in DefaultSystemCodePage. Whereas TEncoding.ANSI should stay a fixed 
> ANSI code page. With it there is no need for TEncoding.SystemEncoding.
The defaultsystemencoding changes the meaning of the codepage for the 
application libraries (read: the pascal parts), NOT for the delphi api.

>
> With this change, in the current Lazarus UTF-8 solution, 
> TEncoding.Default will be UTF-8. In the future Unicode and 
> Delphi-compatible FPC/Lazarus, TEncoding.Default will get the Delphi 
> meaning (ANSI/UTF-8). IMO the concept is very sensible.
Delphi is UTF-16. UTF-8 is only used for document formats, not for APIs.


More information about the fpc-devel mailing list