• Delphi JCL JEDI使用 jclDebug


    开源

    https://github.com/project-jedi/jcl

     jclDebug

    下载jcl,还要下载https://github.com/project-jedi/jedi里的2个inc文件

    放到jcl-masterjclsourceincludejedi目录里。

    运行jclinstall.bat 安装。没有dpk工程文件。

    运行bat文件,弹出下面的界面,点install即可。
     
    like this
    http://stackoverflow.com/questions/32881718/installing-jvcl-into-delphi-10-seattle
     
     

    JclDebug

    jclsourcewindowsJclDebug.pas
    这包含了个Demo
    jclexampleswindowsdebugstacktrack.dproj
    unit StackTrackDemoMain;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, AppEvnts, ActnList;
    
    type
      TMainForm = class(TForm)
        ExceptionLogMemo: TMemo;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        ListBox1: TListBox;
        Button4: TButton;
        ApplicationEvents: TApplicationEvents;
        Label1: TLabel;
        ActionList1: TActionList;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure ApplicationEventsException(Sender: TObject; E: Exception);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      MainForm: TMainForm;
    
    implementation
    
    {$R *.DFM}
    
    uses
      JclDebug;
    
    { TMainForm }
    
    //--------------------------------------------------------------------------------------------------
    // Simulation of various unhandled exceptions
    //--------------------------------------------------------------------------------------------------
    
    procedure TMainForm.Button1Click(Sender: TObject);
    begin
      PInteger(nil)^ := 0;
    end;
    
    procedure TMainForm.Button2Click(Sender: TObject);
    begin
      ListBox1.Items[1] := 'a';
    end;
    
    procedure AAA;
    begin
      PInteger(nil)^ := 0;
    end;
    
    procedure TMainForm.Button3Click(Sender: TObject);
    begin
      AAA;
    end;
    
    procedure TMainForm.Button4Click(Sender: TObject);
    begin
      ActionList1.Actions[0].Execute;
    end;
    
    //--------------------------------------------------------------------------------------------------
    // Simple VCL application unhandled exception handler using JclDebug
    //--------------------------------------------------------------------------------------------------
    
    procedure TMainForm.ApplicationEventsException(Sender: TObject; E: Exception);
    begin
      // Log time stamp
      ExceptionLogMemo.Lines.Add(DateTimeToStr(Now));
    
      // Log unhandled exception stack info to ExceptionLogMemo
      JclLastExceptStackListToStrings(ExceptionLogMemo.Lines, False, True, True, False);
    
      // Insert empty line
      ExceptionLogMemo.Lines.Add('');
    
      // Display default VCL unhandled exception dialog
      Application.ShowException(E);
    end;
    
    //--------------------------------------------------------------------------------------------------
    // JclDebug initialization and finalization for VCL application
    //--------------------------------------------------------------------------------------------------
    
    initialization
    
      // Enable raw mode (default mode uses stack frames which aren't always generated by the compiler)
      Include(JclStackTrackingOptions, stRawMode);
      // Disable stack tracking in dynamically loaded modules (it makes stack tracking code a bit faster)
      Include(JclStackTrackingOptions, stStaticModuleList);
    
      // Initialize Exception tracking
      JclStartExceptionTracking;
    
    finalization
    
      // Uninitialize Exception tracking
      JclStopExceptionTracking;
    
    end.
    View Code

    获取当前过程函数的名称

    记得把上面的jcl debug的选项打开。

       self.Caption:= JclDebug.GetLocationInfoStr(Caller(1));

    http://delphi.wikia.com/wiki/JEDI_Code_Library

    unit u_JclDebugTest;
    
    interface
    
    function CurrentFunctionName: string;
    
    type
      TSomeClass = class
      private
      public
        constructor Create;
        destructor Destroy; override;
        procedure Test;
      end;
    
    implementation
    
    uses
      JclDebug;
    
    { TSomeClass }
    
    constructor TSomeClass.Create;
    begin
      WriteLn(CurrentFunctionName);
    end;
    
    destructor TSomeClass.Destroy;
    begin
      WriteLn(CurrentFunctionName);
      inherited;
    end;
    
    procedure TSomeClass.Test;
    begin
      WriteLn(CurrentFunctionName);
    end;
    
    {$W+}
    
    function CurrentFunctionName: string;
    begin
      Result := jcldebug.GetLocationInfoStr(Caller(1));
    end;
    
    end.
    
    
    program jcldebugtest;
    
    {$APPTYPE console}
    
    uses
      u_JclDebugTest;
    
    procedure SomeProcedure;
    begin
      WriteLn(CurrentFunctionName);
      with TSomeClass.Create do begin
        Test;
        Free;
      end;
    end;
    
    begin
      WriteLn(CurrentFunctionName);
      SomeProcedure;
      WriteLn(CurrentFunctionName);
    end.
    
    This program will output:
    
    [0042362D] jcldebugtest.jcldebugtest (Line 18, "jcldebugtest.dpr")
    [004223A7] jcldebugtest.SomeProcedure (Line 10, "jcldebugtest.dpr")
    [0042226C] u_JclDebugTest.TSomeClass.Create (Line 34, "u_JclDebugTest.pas")
    [00422352] u_JclDebugTest.TSomeClass.Test (Line 45, "u_JclDebugTest.pas")
    [004222E5] u_JclDebugTest.TSomeClass.Destroy (Line 39, "u_JclDebugTest.pas")
    [00423651] jcldebugtest.jcldebugtest (Line 20, "jcldebugtest.dpr")
    View Code

     http://stackoverflow.com/questions/19450140/combining-log4delphi-and-jcl-debug

    http://stackoverflow.com/questions/19496046/get-name-of-the-previous-calling-method

  • 相关阅读:
    SOUI更新到2.0
    第三十一篇:SOUI布局之相对于特定兄弟窗口
    SOUI与WTL
    在SOUI中非半透明窗口如何实现圆角窗口?
    拥抱ARM妹纸第二季 之 第一次 点亮太阳
    拥抱ARM妹子第二季 之 序:我和春天有个约会
    解决自定义控件窗体缩放时闪烁
    The 50 Most Essential Pieces of Classical Music
    嵌入式开发目录
    C中浮点数转字符串
  • 原文地址:https://www.cnblogs.com/cb168/p/6165496.html
Copyright © 2020-2023  润新知