Delphi function in AssignFile

procedure TForm1.SaveLog(sFlag:string;MSG:string);
var
QF1:Textfile;         ----声明文本文件类型
Qfiletmp,sPath:string;
begin
try
sPath :=ExtractFileDir(ParamStr(0))+'\Sajet_Log\';
if not directoryExists(sPath) then
begin
forcedirectories(sPath);
end;
Qfiletmp:=sPath+formatdatetime('yyyy_mm_dd',now)+'.LOG';

Not the FileExists IF (Qfiletmp) the then
the begin
AssignFile (QF1, Qfiletmp); ---- the variable QF1 Qfiletmp file to establish a connection, may be used later for file F variable operation.
rewrite (QF1); ---- // Rewrite process can create a new file and open it; use the Reset to open the text file is read-only, using the Rewrite and Append to open the text file can only be written
closeFile (QF1); ---- close the file
End;
AssignFile (QF1, Qfiletmp);
the append (QF1);
IF = sflag 'the NG' the then
writeln (QF1, FormatDateTime ( 'YYYY-mm-dd HH: mm: SS', now) + ' [Error] '+ the MSG)
the else
writeln (QF1, FormatDateTime (' YYYY-mm-dd HH: mm: SS ', now) +' [] '+ the MSG);
CloseFile (QF1);
the except
End;
End;

Guess you like

Origin www.cnblogs.com/ximi07/p/11811219.html