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

Ondrej Pokorny lazarus at kluug.net
Fri Jan 3 10:07:53 CET 2020


On 03.01.2020 00:35, Werner Pamler wrote:
> Am 02.01.2020 um 20:10 schrieb Ondrej Pokorny:
>> TStrings.SaveTo*() writes BOM by default. Formerly the BOM was not 
>> written.
>
> There is also the problem that currently it is not possible, without 
> further action, to retain the BOM state of a file loaded into a 
> stringlist, modified and written back because the presence of a BOM is 
> forgotten after reading - see the other discussion 
> (https://lists.freepascal.org/pipermail/fpc-devel/2020-January/042363.html). 
> Wouldn't it make sense to introduce a )Read)BOM property (a boolean 
> parameter or an element of the new Options) which gets its value when 
> the file is loaded or the strings are assigned? Then the user can set 
> the StringList.WriteBOM equal to the StringList.BOM when he wants to 
> keep the BOM for writing back.

Yes, that is perfectly reasonable. I'd prefer a new element in Options 
but there is the risk that Delphi adds a new option in the future and 
then we'll have a problem. So maybe a "PreserveBOM" or 
"SetWriteBOMOnLoad" property will be better. When set to true, WriteBOM 
will be set in LoadFrom*() according to BOM presence of the loaded file.

Ondrej



More information about the fpc-devel mailing list