Delphi中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';

if not FileExists(Qfiletmp) then
begin
assignfile(QF1,Qfiletmp);     ----將Qfiletmp文件與變量QF1建立連接,后面可以使用F變量對文件進行操作。
rewrite(QF1);                       ----//Rewrite 過程能創建一個新文件並打開它;使用Reset 打開的文本文件是只讀的,使用Rewrite 和Append 打開的文本文件只能寫入
closeFile(QF1);                   ----關閉文件
end;
AssignFile(QF1,Qfiletmp);
append(QF1);
if sFlag ='NG' then
writeln(QF1,formatdatetime('yyyy-mm-dd hh:mm:ss',now)+'[ Error ]'+MSG)
else
writeln(QF1,formatdatetime('yyyy-mm-dd hh:mm:ss',now)+'[ ]'+MSG);
closeFile(QF1);
except
end;
end;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM