TSubstringList.LoadFromFile Method

Overload List

#SignatureDescription
1procedure LoadFromFile(const FileName: string); overload;Replaces the items with the lines of file FileName: LoadFromStream on the file, in the encoding its byte order mark names, else DefaultEncoding.
2procedure LoadFromFile(const FileName: string; const Encoding: TEncoding); overload;Replaces the items with the lines of file FileName in Encoding; nil reads in the encoding the byte order mark names, else DefaultEncoding.

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

Replaces the items with the lines of file FileName: LoadFromStream on the file, in the encoding its byte order mark names, else DefaultEncoding.

#NameDescription
1FileName

The file's name.

Result: stored in self (calling object)

Examples

A file written and read back.

uses Substr, System.SysUtils;

procedure Example;
const FileName = 'SubstringListLoad.txt';
var List: TSubstringList;
begin
    List := TSubstringList.Create(4);
    try
        List.Add('first');
        List.Add('second');
        List.SaveToFile(FileName, TEncoding.UTF8);
        List.LoadFromFile(FileName);
        Assert((List.Count = 2) and (List[1] = 'second'));
        Assert(List.Encoding = TEncoding.UTF8);
    finally
        List.Free;
        DeleteFile(FileName);
    end;
end;
See Also: TSubstringList.LoadFromStream, TSubstringList.LoadFromStream, TSubstringList.SaveToFile, TSubstringList.SaveToFile, TSubstringList.Encoding

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

Replaces the items with the lines of file FileName in Encoding; nil reads in the encoding the byte order mark names, else DefaultEncoding.

#NameDescription
1FileName

The file's name.

2Encoding

The encoding to read the file in; nil as LoadFromFile(FileName).

Result: stored in self (calling object)