📄 log.~pas
字号:
unit log;
interface
uses
Windows, SysUtils, Classes, Dialogs;
type
TXMLFileOperator=class
private
fPath:string;
public
constructor create(fPath:string);
procedure addLog(errName,errPos,Caller,errMsg,other:string);
end;
implementation
{ TXMLFileOperator }
procedure TXMLFileOperator.addLog(errName, errPos, Caller,
errMsg,other: string);
var
strs:TStrings;
begin
if (errName='') and (errPos='') and (Caller='') and (errMsg='') then exit;
if errName='' then exit;
try
strs:=TStringList.Create;
try
strs.LoadFromFile(fPath);
strs.Insert(strs.Count-1,format('<error name=''%s'' time=''%s''>',[errName,FormatDateTime('yyyy-mm-dd hh:mm:ss',now)]));
if errPos<>'' then
begin
strs.Insert(strs.Count-1,'<pos>');
strs.Insert(strs.Count-1,errPos);
strs.Insert(strs.count-1,'</pos>')
end;
if Caller<>'' then
begin
strs.Insert(strs.Count-1,'<call>');
strs.Insert(strs.Count-1,Caller);
strs.Insert(strs.count-1,'</call>')
end;
if errMsg<>'' then
begin
strs.Insert(strs.Count-1,'<msg>');
strs.Insert(strs.Count-1,errMsg);
strs.Insert(strs.count-1,'</msg>')
end;
if other<>'' then
begin
strs.Insert(strs.Count-1,'<other>');
strs.Insert(strs.Count-1,other);
strs.Insert(strs.count-1,'</other>')
end;
strs.Insert(strs.Count-1,'</error>');
strs.SaveToFile(fPath);
finally
strs.Free;
end;
except
on Exception do ;
end;
end;
constructor TXMLFileOperator.create(fPath:string);
var
OpFile:TextFile;
begin
self.fPath:=fPath;
try
if not FileExists(fPath) then
begin
try
AssignFile(OpFile,fPath);
Rewrite(OpFile);
Writeln(OpFile,'<?xml version="1.0" encoding="GBK"?>');
Writeln(OpFile,'<log>');
Writeln(OpFile,'</log>');
finally
CloseFile(OpFile);
end;
end;
except
on Exception do ;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -