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

Ondrej Pokorny lazarus at kluug.net
Thu Dec 26 17:23:04 CET 2019


On 26.12.2019 17:02, Mattias Gaertner via fpc-devel wrote:
> On Thu, 26 Dec 2019 16:55:04 +0100
> Ondrej Pokorny <lazarus at kluug.net> wrote:
>
>> On 26.12.2019 16:41, Mattias Gaertner via fpc-devel wrote:
>>> On Thu, 26 Dec 2019 16:15:03 +0100
>>> Ondrej Pokorny <lazarus at kluug.net> wrote:
>>>   
>>>> Hello,
>>>>
>>>> a lot of people have a problem with the TStrings.LoadFrom*()
>>>> changes when TEncoding support was added.
>>>>
>>>> Currently, the no-encoding overloads of TStrings.LoadFrom*() and
>>>> TStrings.SaveTo*() use the TEncoding.Default, which is WIN-ANSI and
>>>> not DefaultSystemCodePage.
>>> It seems FPC 3.3.1 does use DefaultSystemCodePage:
>>>
>>> class function TEncoding.GetANSI: TEncoding;
>>> begin
>>>     ....
>>>       if not Assigned(FStandardEncodings[seAnsi]) then
>>>       begin
>>>         // DefaultSystemCodePage can be set to non-ANSI
>>>         if Assigned(widestringmanager.GetStandardCodePageProc) then
>>>           FStandardEncodings[seAnsi] :=
>>> TMBCSEncoding.Create(widestringmanager.GetStandardCodePageProc(scpAnsi))
>>> else FStandardEncodings[seAnsi] :=
>>> TMBCSEncoding.Create(DefaultSystemCodePage); ...
>>> end;
>> Check the code more carefully. It uses DefaultSystemCodePage only
>> when no widestringmanager is present - which is basically never the
>> case (at least on win32, Linux, Mac OS).
>>
>> It uses widestringmanager.GetStandardCodePageProc(scpAnsi) that is
>> WIN-ANSI on win32 (typically 1250, 1251, 1252 - depending on your OS
>> language version).
> Yes, I just saw it. Bummer.

The comment
// DefaultSystemCodePage can be set to non-ANSI
is misleading and doesn't correspond to both the code and the currently 
desired behavior https://bugs.freepascal.org/view.php?id=32961#c115162

I deleted it.

Ondrej



More information about the fpc-devel mailing list