-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathESoft.Launcher.UI.ErrorViewer.pas
177 lines (153 loc) · 4.52 KB
/
ESoft.Launcher.UI.ErrorViewer.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
unit ESoft.Launcher.UI.ErrorViewer;
{ ---------- Developed by Muhammad Ajmal P ---------- }
{ ---------- [email protected] --------------------- }
Interface
uses
System.UITypes,
SysUtils,
Forms,
StdCtrls,
Classes,
Controls,
ExtCtrls,
Graphics,
Buttons,
ActnList,
ExtActns,
StdActns,
ShellApi;
type
TFormExceptionHandler = class(TForm)
Bevel1: TPanel;
btnOK: TButton;
btnDetails: TButton;
memTechnical: TMemo;
btnPrint: TButton;
lblBuildNumber: TLabel;
edtBuildNumber: TEdit;
lblBottomRightOne: TLabel;
lblBottomRightTwo: TLabel;
btnTerminate: TButton;
btnEmail: TButton;
Image1: TImage;
memUser: TMemo;
btnCopyStackTrace: TSpeedButton;
procedure btnOKClick(Sender: TObject);
procedure btnDetailsClick(Sender: TObject);
procedure btnPrintClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnCopyStackTraceClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnEmailClick(Sender: TObject);
procedure btnTerminateClick(Sender: TObject);
private
procedure AppException(aSender: TObject; aExcept: Exception);
end;
implementation
{$R *.DFM}
uses
Windows,
Dialogs,
Clipbrd, { Clipboard object }
JclDebug,
Variants,
UnitMDIMain;
const
cDetailsLALA = '&Details <<';
cDetailsRARA = '&Details >>';
var
_varErrorFrame: TFormExceptionHandler;
{ TfrmError }
procedure TFormExceptionHandler.btnOKClick(Sender: TObject);
begin
try
ModalResult := mrOk;
Screen.Cursor := crDefault;
memTechnical.Lines.Clear;
except on E:Exception do
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
end;
procedure TFormExceptionHandler.btnDetailsClick(Sender: TObject);
begin
try
if Height < lblBottomRightOne.Top + 60 then
begin
Height := lblBottomRightTwo.Top + lblBottomRightTwo.Height + 29;
btnDetails.Caption := cDetailsLALA;
end
else
begin
Height := lblBottomRightOne.Top + lblBottomRightOne.Height + 29;
btnDetails.Caption := cDetailsRARA;
end;
btnOK.SetFocus;
except
; { purposefully ignore any errors in the error handler }
end;
end;
procedure TFormExceptionHandler.btnEmailClick(Sender: TObject);
Const
cExceptionReportLink = 'mailto:[email protected]?subject=Laucnher%20Exception%20Report';
begin
if MessageDlg('Do you want to copy error message to clipboard ?', mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then
btnCopyStackTrace.Click;
ShellExecute(Handle, 'open', cExceptionReportLink, '', '', SW_HIDE);
ModalResult := mrClose;
end;
procedure TFormExceptionHandler.btnPrintClick(Sender: TObject);
begin
try
Print;
btnOK.SetFocus;
except
; { purposefully ignore any errors in the error handler }
end;
end;
procedure TFormExceptionHandler.btnTerminateClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TFormExceptionHandler.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
Height := lblBottomRightOne.Top + lblBottomRightOne.Height + 29;
btnDetails.Caption := cDetailsRARA;
except
; { purposefully ignore any errors in the error handler }
end;
end;
procedure TFormExceptionHandler.btnCopyStackTraceClick(Sender: TObject);
begin
Clipboard.AsText := memTechnical.Lines.Text;
end;
procedure TFormExceptionHandler.FormCreate(Sender: TObject);
begin
Application.OnException := AppException;
end;
procedure TFormExceptionHandler.AppException(aSender: TObject; aExcept: Exception);
var
bFormShowing: Boolean;
begin
edtBuildNumber.Text := cAppVersion;
memTechnical.Lines.Clear;
memTechnical.Lines.Add(aExcept.Message);
if Assigned(aSender) then
memTechnical.Lines.Add('Exception from class: ' + aSender.ClassName);
memTechnical.Lines.Add('Launcher Version: ' + edtBuildNumber.Text);
memTechnical.Lines.Add('');
JclLastExceptStackListToStrings(memTechnical.Lines, False, True, True);
bFormShowing := FormMDIMain.Visible;
FormMDIMain.Show;
_varErrorFrame.ShowModal;
FormMDIMain.Visible := bFormShowing;
end;
initialization
_varErrorFrame := TFormExceptionHandler.Create(Application);
JclStackTrackingOptions := JclStackTrackingOptions + [stRawMode, stStaticModuleList];
JclStartExceptionTracking;
finalization
// Don't free _varErrorFrame. Application will free this. { Ajmal }
// FreeAndNil(_varErrorFrame);
JclStopExceptionTracking;
end.