WriteErrorFile() try Except end 错误处理并且保存.txt文件

 
{写1个错误的日志文件 并记录错误的地方}
//调用 WriteErrorFile('Button1');
//try except 在这里放着 end;
procedure WriteErrorFile(str:string);
var
    path:string;{FilePath}
    f:TextFile; {txtFile}
    et:string;  {error time}
    ef:string;  {error fileName}
    h:THandle;  {handle}
    el:string;  {error lists}
begin
    ef:='error.txt';
    path:=ExtractFilePath(Application.ExeName)+ef;  //加上程序已经运行的时间
    et:=FormatDateTime('[yyyy"-"mm"-"dd" "dddd" "hh"-"mm"-"ss]  ',now);
    el:= et + str+'::error ';

    if not FileExists(path) then
      begin
          h:=FileCreate(path);
          FileClose(h);
          AssignFile(F,path);
          Append(F);
          Writeln(F,el);
          CloseFile(F);
      end
    else
      begin
        AssignFile(F,path);
        Append(F);
        Writeln(F,el);
        CloseFile(F);
      end;
end;




附件列表

    原文地址:https://www.cnblogs.com/xe2011/p/2541246.html