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

Ondrej Pokorny lazarus at kluug.net
Thu Jan 2 20:10:57 CET 2020

On 27.12.2019 12:01, Ondrej Pokorny wrote:
> On 27.12.2019 10:40, Michael Van Canneyt wrote:
>>> Yes, indeed. Therefore I suggested
>>> * TEncoding.Default for the DefaultSystemCodePage variable
>>> and
>>> * TEncoding.ANSI for the system encoding.
>>> Currently we have
>>> * TEncoding.SystemEncoding for the DefaultSystemCodePage variable
>>> and
>>> * both TEncoding.ANSI and TEncoding.Default for the system encoding. 
>>> (TEncoding.ANSI and TEncoding.Default are equal in FPC.)
>> In that case,  why not simply change:
>>  class function TEncoding.GetDefault: TEncoding;
>>  begin
>>    Result := GetSystemEncoding;
>>  end;
>> Nothing need be removed. I consider SystemEncoding a better name than 
>> Default,
>> and the latter should only be kept for Delphi compatibility. IMHO it 
>> would be
>> better to avoid Default, in fact I would change references to Default to
>> SystemEncoding for clarity. Default is completely non-descriptive.
>> If I understand your reasoning correct, that should solve the 
>> problems you
>> report ?
> Yes, that perfectly solves the issues Lazarus developers and users 
> face. I am OK with this solution as well. Thanks!

I applied the change

class function TEncoding.GetDefault: TEncoding;
    Result := GetSystemEncoding;

in r43842 before it gets forgotten. I removed the ANSI-hack from Lazarus 
as well - in r62474.

Please note that in Lazarus (where the system encoding is UTF-8), 
TStrings.SaveTo*() writes BOM by default. Formerly the BOM was not 
written. Bart reported the issue here: 


More information about the fpc-devel mailing list