• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

DelphiJCLJEDI使用jclDebug

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

开源

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

 jclDebug

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

放到jcl-master\jcl\source\include\jedi目录里。

运行jcl\install.bat 安装。没有dpk工程文件。

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

JclDebug

jcl\source\windows\JclDebug.pas
这包含了个Demo
jcl\examples\windows\debug\stacktrack.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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphi连接数据库发布时间:2022-07-18
下一篇:
Delphi7下SuperObject的JSON使用方法发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap