TSubstringList.SaveToFile Method

Overload List

#SignatureDescription
1procedure SaveToFile(const FileName: string); overload;Writes Text to file FileName in Encoding (the encoding of the last load), else DefaultEncoding: SaveToStream on a new file.
2procedure SaveToFile(const FileName: string; const Encoding: TEncoding); overload;Writes Text to file FileName in Encoding: SaveToStream on a new file; nil writes in DefaultEncoding.

Overload 1: procedure SaveToFile(const FileName: string); overload;

Writes Text to file FileName in Encoding (the encoding of the last load), else DefaultEncoding: SaveToStream on a new file.

#NameDescription
1FileName

The file's name; the file is created anew.

Result: stored in self (calling object)

Examples

Saved and loaded into another list.

uses Substr, System.SysUtils;

procedure Example;
const FileName = 'SubstringListSave.txt';
var List, Other: TSubstringList;
begin
    List := TSubstringList.Create(2);
    Other := TSubstringList.Create(2);
    try
        List.Add('a');
        List.Add('b');
        List.SaveToFile(FileName);
        Other.LoadFromFile(FileName);
        Assert(Other.Text = List.Text);
    finally
        Other.Free;
        List.Free;
        DeleteFile(FileName);
    end;
end;
See Also: TSubstringList.SaveToStream, TSubstringList.SaveToStream, TSubstringList.LoadFromFile, TSubstringList.LoadFromFile, TSubstringList.WriteBOM

Overload 2: procedure SaveToFile(const FileName: string; const Encoding: TEncoding); overload;

Writes Text to file FileName in Encoding: SaveToStream on a new file; nil writes in DefaultEncoding.

#NameDescription
1FileName

The file's name; the file is created anew.

2Encoding

The encoding to write in; nil writes in DefaultEncoding.

Result: stored in self (calling object)