[fpc-devel] TStrings and BOM

Ondrej Pokorny lazarus at kluug.net
Thu Jan 2 19:15:03 CET 2020


On 02.01.2020 14:58, Michael Van Canneyt wrote:
> On Thu, 2 Jan 2020, Bart via fpc-devel wrote:
>
>> On Thu, Jan 2, 2020 at 12:12 PM Michael Van Canneyt
>> <michael at freepascal.org> wrote:
>>
>>> In Delphi it doesn't matter where the encoding comes from.
>>> If writeBOM is true and there is a preamble for the encoding 
>>> (whatever it
>>> is), it is used.
>>
>> I think I have to rephrase my question.
>> In fpc TStrings.SaveToStream(AStream) does NOT use DefaultEncoding if
>> Encoding is nil.
>> So this code:
>>
>> //Source codepage is Windows 1512
>> SL := TStringList.Create;
>> SL.SkipLastLineBreak := True;
>> SL.WriteBOM := True;
>> SL.DefaultEncoding := TEncoding.UTF8;
>> S := 'รค'; // = #$0E
>> SL.Add(S);
>> SL.SaveToStream(St)
>>
>> Will result in St having as content 1 single byte: 0E (hex)
>>
>> Whereas
>> SL.SaveToStream(St, nil) will result in St having a content of 5
>> bytes: EF BB BF C3 A4
>>
>> Is that Delphi compatible?
>> From the help text of the Embarcadero site I cannot figure that out.
>
> That seems not compatible to me.

Should be fixed in r43839. Please report any issues.

Ondrej



More information about the fpc-devel mailing list