代码之家  ›  专栏  ›  技术社区  ›  HX_unbanned

TApplicationEvents作为动态组件或静态组件进行跟踪,在Delphi中调用例程

  •  2
  • HX_unbanned  · 技术社区  · 16 年前

    不幸的是,我不是在我的开发PC上写这个问题的,所以我可能会犯一些错误。请对此表示歉意。。。

    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;
    

    …以及 http://delphi.about.com/cs/adptips2001/a/bltip0101_2.htm

    2 回复  |  直到 16 年前
        1
  •  6
  •   Pauk    16 年前

    可能值得考虑第三方组件,而不是自己写东西。两者 EurekaLog madExcept 几乎完全按照你想要的去做。两者都能提供出色的输出,并支持连接到bug跟踪系统,如 FogBugz , Mantis BugZilla 有了它,你就可以整理你收到的bug报告,发现常见的模式,并希望更快地修复bug。

        2
  •  3
  •   John Thomas    16 年前

    Exception class: EVariantTypeCastError
    Exception address: 004170ED
    ------------------------------------------------------------------------------
    Stack list, generated 12/7/2009 11:32:19
    [004170E8]{A.exe       } Variants.HandleConversionException (Line 614, "sys\variants.pas" + 10)
    [0057ACAC]{A.exe       } cxDataStorage.TcxSmallintValueType.SetDataValue (Line 1067, "cxDataStorage.pas" + 2)
    [005AC6C5]{A.exe       } cxCustomData.TcxCustomDataController.SetStoredValue (Line 12752, "cxCustomData.pas" + 2)
    [005A8AD3]{A.exe       } cxCustomData.TcxCustomDataController.SetValue (Line 10401, "cxCustomData.pas" + 12)
    [0059DA0B]{A.exe       } cxCustomData.TcxCustomDataProvider.SetEditValue (Line 3180, "cxCustomData.pas" + 4)
    [005A8F9B]{A.exe       } cxCustomData.TcxCustomDataController.SetEditValue (Line 10560, "cxCustomData.pas" + 2)
    [0066EBBE]{A.exe       } cxGridCustomTableView.TcxCustomGridTableItem.SetEditValue (Line 14396, "cxGridCustomTableView.pas" + 1)
    [006637C5]{A.exe       } cxGridCustomTableView.TcxGridEditingController.UpdateValue (Line 7474, "cxGridCustomTableView.pas" + 4)
    [00673F30]{A.exe       } cxGridCustomTableView.TcxCustomGridTableView.UpdateRecord (Line 17771, "cxGridCustomTableView.pas" + 1)
    [0059D97F]{A.exe       } cxCustomData.TcxCustomDataProvider.PostEditingData (Line 3170, "cxCustomData.pas" + 1)
    [00A80870]{A.exe       } fFilterLine.TFilterLine.UMLayoutChanged (Line 1034, "fFilterLine.pas" + 0)
    [00482DBF]{A.exe       } Controls.TWinControl.WndProc (Line 7304, "Controls.pas" + 111)
    [004824E8]{A.exe       } Controls.TWinControl.MainWndProc (Line 7073, "Controls.pas" + 3)
    [00431D84]{A.exe       } Classes.StdWndProc (Line 11583, "common\Classes.pas" + 8)
    [0049F981]{A.exe       } Forms.TApplication.MessageBox (Line 8293, "Forms.pas" + 22)
    [0049FA99]{A.exe       } Forms.TApplication.ShowException (Line 8312, "Forms.pas" + 3)
    [00A7D7B1]{A.exe       } ExceptionDlg.TfrmException.ExceptionHandler (Line 428, "..\Shared\ExceptionDlg.pas" + 2)
    
    ...
    <snipped>
    ...
    
    ------------------------------------------------------------------------------
    System   : Windows XP Professional, Version: 5.1, Build: A28, "Service Pack 2"
    Processor: Intel, Intel(R) Core(TM)2 Quad CPU    Q6700  @ 2.66GHz, 2666 MHz MMX 64 bits
    Memory: 1043; free 196
    Display  : 1920X1200 pixels, 32 bpp
    ------------------------------------------------------------------------------
    Active Controls hierarchy:
    TcxCustomInnerTextEdit ""
    TcxTextEdit ""
    TcxGridSite ""
    TcxGrid "cxgHeader"
    TPanel "pnlMain"
    TTabSheet "tshAccMov"
    TPageControl "pcoMov"
    TfrmMain "frmMain"
    ------------------------------------------------------------------------------
    

    …嗯,imho,不值得重新发明轮子。 这已经完成了,而且是免费的。下载(如果您还没有) JEDI s JVCL+JCL from SourceForge 您将有一个新项目: .

    而且(imho)这比“如果你有时间的话”要成熟/先进得多。您还可以自定义生成的异常处理程序以满足您的需求。对此也有一个支持新闻组。顺便说一句,IIRC,对话只需要JCL,但我不确定。此外,您还可以使用商业选项(madExcent、EurekaLog等),但这些只是高级错误记录器,而JVCL除了免费外,还将为您提供600多个组件供您使用。