procedure write_log(str: string);
var
F: TextFile;
mfile: string;
begin
try
//判断保存日志文件的目录是否存在
if not DirectoryExists(ExtractFilePath(ParamStr(0)) + 'log') then
MkDir(ExtractFilePath(ParamStr(0)) + 'log');
//按日期及时间设定保存日志的文件名
mfile := ExtractFilePath(ParamStr(0)) + 'log\' + formatdatetime('yyyy-mm-dd', now) + '.txt';
AssignFile(F,mfile);
if not FileExists(mfile) then
Rewrite(F);//如果文件不存在,则创建一个新的文件,并写入
Append(F); //追加写入
Writeln(F,str);//写入并换行
CloseFile(F);
except
end;
end;
//读txt
Procedure ReadTxt(FileName:String);
Var
F:Textfile;
str: String;
Begin
AssignFile(F, FileName); {将文件名与变量 F 关联}
Reset(F); {打开并读取文件 F }
while not Eof(F) do
begin
Readln(F, str);
Form1.Memo2.Lines.Add(str);
end;
ShowMessage(str);
Closefile(F); {关闭文件 F}
End;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.26256680488586 seconds