TStringList.LoadFromFile

From Soldat Community Wiki
Jump to: navigation, search
procedure LoadFromFile(FileName: string)
 FileName: path to a source file

Description

LoadFromFile loads the contents of a file into the stringlist. Each line in the file (as marked by the end-of-line marker of the particular OS the application runs on) becomes one string in the stringlist.
This action replaces the contents of the stringlist, it does not append the strings to the current content.

Example

myfile.txt in soldatserver's root folder:

line1
line2
line3

script file:

const
  // assuming Sandbox Level < 2
  PATH='myfile.txt';

var
  s: TStringList;

begin
  s := File.CreateStringList();
  s.Append('a');
  s.Append('b');
  s.Append('c');
  WriteLn(s.CommaText);
  // a,b,c

  s.LoadFromFile(PATH);
  WriteLn(s.CommaText);
  // line1,line2,line3
    
  s.Free;
end.