TSubstringList.DefaultEncoding Property

property DefaultEncoding: TEncoding read FDefaultEncoding write SetDefaultEncoding;

The encoding of a load given none whose stream has no byte order mark, and of a save before any load; TEncoding.Default at first.

Returns: TEncoding

Remarks:

An encoding other than a standard one (TEncoding.UTF8 and the like) is kept as a copy; nil sets TEncoding.Default.

Examples

A save before any load writes in DefaultEncoding.

uses Substr, System.SysUtils, System.Classes;

procedure Example;
var List: TSubstringList;
    Stream: TBytesStream;
begin
    List := TSubstringList.Create(2);
    Stream := TBytesStream.Create;
    try
        List.DefaultEncoding := TEncoding.UTF8;
        List.Add('a');
        List.SaveToStream(Stream);
        Assert((Stream.Size = 6) and (Stream.Bytes[0] = $EF));
    finally
        Stream.Free;
        List.Free;
    end;
end;
See Also: TSubstringList.Encoding, TSubstringList.WriteBOM