| 1 | unit UExceptionForm;
|
|---|
| 2 |
|
|---|
| 3 | {$mode objfpc}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|---|
| 9 | CustomLineInfo, ComCtrls, ExtCtrls, UStackTrace, UExceptionLogger;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TExceptionForm }
|
|---|
| 14 |
|
|---|
| 15 | TExceptionForm = class(TForm)
|
|---|
| 16 | ButtonDetails: TButton;
|
|---|
| 17 | ButtonClose: TButton;
|
|---|
| 18 | ButtonKill: TButton;
|
|---|
| 19 | CheckBoxIgnore: TCheckBox;
|
|---|
| 20 | Image1: TImage;
|
|---|
| 21 | Label1: TLabel;
|
|---|
| 22 | LabelMessage: TLabel;
|
|---|
| 23 | ListView1: TListView;
|
|---|
| 24 | MemoExceptionInfo: TMemo;
|
|---|
| 25 | PageControl1: TPageControl;
|
|---|
| 26 | PanelBasic: TPanel;
|
|---|
| 27 | PanelDescription: TPanel;
|
|---|
| 28 | PanelButtons: TPanel;
|
|---|
| 29 | TabSheet1: TTabSheet;
|
|---|
| 30 | TabSheet2: TTabSheet;
|
|---|
| 31 | procedure ButtonCloseClick(Sender: TObject);
|
|---|
| 32 | procedure ButtonDetailsClick(Sender: TObject);
|
|---|
| 33 | procedure ButtonKillClick(Sender: TObject);
|
|---|
| 34 | procedure FormCreate(Sender: TObject);
|
|---|
| 35 | procedure FormDestroy(Sender: TObject);
|
|---|
| 36 | procedure FormShow(Sender: TObject);
|
|---|
| 37 | procedure Image1Click(Sender: TObject);
|
|---|
| 38 | public
|
|---|
| 39 | Logger: TExceptionLogger;
|
|---|
| 40 | procedure LoadStackTraceToListView(StackTrace: TStackTrace);
|
|---|
| 41 | end;
|
|---|
| 42 |
|
|---|
| 43 | var
|
|---|
| 44 | ExceptionForm: TExceptionForm;
|
|---|
| 45 |
|
|---|
| 46 | implementation
|
|---|
| 47 |
|
|---|
| 48 | {$R *.lfm}
|
|---|
| 49 |
|
|---|
| 50 | procedure TExceptionForm.FormShow(Sender: TObject);
|
|---|
| 51 | begin
|
|---|
| 52 | Caption := SExceptionInfo;
|
|---|
| 53 | PageControl1.Pages[0].Caption := SGeneral;
|
|---|
| 54 | PageControl1.Pages[1].Caption := SCallStack;
|
|---|
| 55 | Label1.Caption := SErrorOccured;
|
|---|
| 56 | ButtonClose.Caption := SClose;
|
|---|
| 57 | ButtonDetails.Caption := SDetails;
|
|---|
| 58 | ButtonKill.Caption := STerminate;
|
|---|
| 59 | CheckBoxIgnore.Caption := SIgnoreNextTime;
|
|---|
| 60 | ListView1.Column[0].Caption := SIndex;
|
|---|
| 61 | ListView1.Column[1].Caption := SAddress;
|
|---|
| 62 | ListView1.Column[2].Caption := SLine;
|
|---|
| 63 | ListView1.Column[3].Caption := SClass;
|
|---|
| 64 | ListView1.Column[4].Caption := SProcedureMethod;
|
|---|
| 65 | ListView1.Column[5].Caption := SUnit;
|
|---|
| 66 |
|
|---|
| 67 | Height := PanelBasic.Height + PanelButtons.Height;
|
|---|
| 68 | PageControl1.ActivePageIndex := 0;
|
|---|
| 69 | CheckBoxIgnore.Checked := False;
|
|---|
| 70 | end;
|
|---|
| 71 |
|
|---|
| 72 | procedure TExceptionForm.Image1Click(Sender: TObject);
|
|---|
| 73 | begin
|
|---|
| 74 |
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TExceptionForm.FormCreate(Sender: TObject);
|
|---|
| 78 | begin
|
|---|
| 79 |
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | procedure TExceptionForm.ButtonCloseClick(Sender: TObject);
|
|---|
| 83 | begin
|
|---|
| 84 | Close;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TExceptionForm.ButtonDetailsClick(Sender: TObject);
|
|---|
| 88 | begin
|
|---|
| 89 | if PanelDescription.Height <= 1 then
|
|---|
| 90 | Height := PanelBasic.Height + PanelButtons.Height + 200
|
|---|
| 91 | else Height := PanelBasic.Height + PanelButtons.Height;
|
|---|
| 92 | Application.ProcessMessages;
|
|---|
| 93 | if MemoExceptionInfo.Text = '' then Logger.LoadDetails;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TExceptionForm.ButtonKillClick(Sender: TObject);
|
|---|
| 97 | begin
|
|---|
| 98 | //Halt;
|
|---|
| 99 | Application.Terminate;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TExceptionForm.FormDestroy(Sender: TObject);
|
|---|
| 103 | begin
|
|---|
| 104 | end;
|
|---|
| 105 |
|
|---|
| 106 | procedure TExceptionForm.LoadStackTraceToListView(StackTrace: TStackTrace);
|
|---|
| 107 | var
|
|---|
| 108 | I: Integer;
|
|---|
| 109 | NewItem: TListItem;
|
|---|
| 110 | begin
|
|---|
| 111 | with ListView1, Items do
|
|---|
| 112 | try
|
|---|
| 113 | BeginUpdate;
|
|---|
| 114 | Clear;
|
|---|
| 115 | for I := 0 to StackTrace.Count - 1 do
|
|---|
| 116 | with TStackFrameInfo(StackTrace[I]) do begin
|
|---|
| 117 | NewItem := Add;
|
|---|
| 118 | with NewItem do begin
|
|---|
| 119 | Caption := IntToStr(Index);
|
|---|
| 120 | SubItems.Add(IntToHex(Address, 8));
|
|---|
| 121 | SubItems.Add(IntToStr(LineNumber));
|
|---|
| 122 | SubItems.Add(FunctionClassName);
|
|---|
| 123 | SubItems.Add(FunctionName);
|
|---|
| 124 | SubItems.Add(Source);
|
|---|
| 125 | end;
|
|---|
| 126 | end;
|
|---|
| 127 | finally
|
|---|
| 128 | EndUpdate;
|
|---|
| 129 | end;
|
|---|
| 130 | end;
|
|---|
| 131 |
|
|---|
| 132 | initialization
|
|---|
| 133 |
|
|---|
| 134 | ExceptionForm := TExceptionForm.Create(nil);
|
|---|
| 135 |
|
|---|
| 136 | finalization
|
|---|
| 137 |
|
|---|
| 138 | FreeAndNil(ExceptionForm);
|
|---|
| 139 |
|
|---|
| 140 | end.
|
|---|
| 141 |
|
|---|