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

Ondrej Pokorny lazarus at kluug.net
Fri Jan 3 10:55:38 CET 2020

On 03.01.2020 10:14, Michael Van Canneyt wrote:
> On Fri, 3 Jan 2020, Ondrej Pokorny wrote:
>> 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.
> I don't see why a new option is a problem ? They are not streamed anyway.
> So I would do the opposite, add an option. soPreserveBOM.

If you are fine with it, me as well.

Yes, the problem is if somebody streams the property or uses 
Ord(soPreserveBOM) for something etc. I admit that it is a very 
hypothetical issue.


More information about the fpc-devel mailing list