HX_*_*ned 2 delphi static components dynamic event-handling
不幸的是,我没有从我的开发PC中写这个问题所以我可能会犯一些错误.请抱歉...所以 - 我的问题 - 您使用什么方法在应用程序中实现错误记录?
在web(http://delphi.about.com)是很好的事件处理程序,但它只是复制文件中的系统错误,但我想通过捕获内存和堆栈(和处理器信息,如果我有时间)扩展其功能).我是否应该知道我是否动态调用它,而不是在表单上添加其组件?
procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception) ;
var
ErrorLogFileName : string;
ErrorFile : TextFile;
ErrorData : string;
begin
ErrorLogFileName := ChangeFileExt(Application.ExeName,'.error.log') ;
AssignFile(ErrorFile, ErrorLogFileName) ;
//either create an error log file, or append to an existing one
if FileExists(ErrorLogFileName) then
Append(ErrorFile)
else
Rewrite(ErrorFile) ;
try
//add the current date/time and the exception message to the log
ErrorData := Format('%s : %s',[DateTimeToStr(Now),E.Message]) ;
WriteLn(ErrorFile,ErrorData) ;
finally
CloseFile(ErrorFile)
end;
//Show the exception
Application.ShowException(E) ;
end;
Run Code Online (Sandbox Code Playgroud)
......和http://delphi.about.com/cs/adptips2001/a/bltip0101_2.htm
众所周知,Delphi还提供类似C的内存管理 - 使用&符号和Pascal函数,但最有效的日志记录是什么?
谢谢!希望这个主题对其他高质量的程序员有用.
| 归档时间: |
|
| 查看次数: |
1244 次 |
| 最近记录: |