On 01.01.2020 23:59, Werner Pamler wrote:
Am 01.01.2020 um 17:01 schrieb Ondrej Pokorny:
Isn't the TStrings.WriteBOM property good enough? Why to have yet
another not-very-useful overload?
To be honest I think Bart's idea of making the BOM an optional
parameter of the Save methods appears to me more efficient than
defining a property just for this only purpose. Do we really have to
imitate all the nonsense dictated by Delphi?
I see it's quite popular to humble every new Delphi feature after Delphi
7 as being nonsense. Not every time the criticism is valid. And never it
is a good argument.
The WriteBOM property has a valid purpose - it is set in LoadFrom*
according to the BOM presence in the loaded file. I.e. if you do:
MyStrings.LoadFromFile('abc'); // WriteBOM and Encoding properties are
set here
MyStrings.SaveToFile('abc'); // they are used here to save the file as
it was loaded
The abc file keeps BOM and encoding of the original one. You cannot
achieve it with the AWriteBOM parameter Bart suggested.
If you want to simplify a call, use a class helper:
TStringsHelper = class helper for TStrings
...
procedure TStringsHelper.SaveToFileWithBOM(aFileName: string);
begin
WriteBOM := True;
SaveToFile(aFileName);
end;
Ondrej
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel