TApplicationEvents作为动态组件或静态跟踪Delphi中的调用例程

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函数,但最有效的日志记录是什么?

谢谢!希望这个主题对其他高质量的程序员有用.

Pau*_*auk 6

可能值得看第三方组件而不是自己写一些东西.无论EurekaLogmadExcept做几乎你是什么之后.两者都提供了很好的输出,并且支持连接到FogBugz,MantisBugZilla等bug跟踪系统.有了这个,你可以实际整理你得到的错误报告,发现常见的模式,并希望更快地修复错误.

就个人而言,安装Jedi JVCL/JCL对于它的异常跟踪来说有点过分,因为它是一个非常大的安装.我刚才提到的上述两种都是商业产品,但你可以得到你付出的代价.