MyChat Scripts: functionTStringList.SaveToFile, save a list to a text file
Save a list to a text file.
Syntax
procedure TStringList.SaveToFile(sFileName: string);
Parameters and return values
Parameter |
Type |
Value |
sFileName |
string |
text file name with full path. |
When saving, file content will be rewritten with new data.
Example
Calculating the factorial and writing data to a text file of the protocol specifying the time of each iteration up to milliseconds.
const
LOG_FILE = 'C:\Temp\factorial.txt';
var
SL: TStringList;
procedure AddString2Log(sData: string);
var
s: string;
begin
s := FormatDateTime('[yyyy-mm-dd hh:nn:ss:zzz]', Now) + ' ' + sData;
SL.Append(s);
end;
function Factorial(x: integer): int64;
var
n: integer;
r: int64;
begin
r := 1;
for n := 2 to x do r := r * n;
result := r;
end;
var
i: integer;
begin
SL := TStringList.Create;
for i := 1 to 20 do AddString2Log(IntToStr(Factorial(i)));
SL.SaveToFile(LOG_FILE);
SL.Free;
end.
Script work result
[2019.09.03 19:22:57] 2 - 2
[2019.09.03 19:22:57] 3 - 6
[2019.09.03 19:22:57] 4 - 24
[2019.09.03 19:22:57] 5 - 120
[2019.09.03 19:22:57] 6 - 720
[2019.09.03 19:22:57] 7 - 5040
[2019.09.03 19:22:57] 8 -40320
[2019.09.03 19:22:57] 9 - 362880
[2019.09.03 19:22:57] 10 - 3628800
[2019.09.03 19:22:57] 11 - 39916800
[2019.09.03 19:22:57] 12 - 479091600
See also
Created with the Personal Edition of HelpNDoc: Elevate Your Help Documentation with a Help Authoring Tool