forked from pyscripter/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgExceptionMail.pas
727 lines (644 loc) · 25.8 KB
/
dlgExceptionMail.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is ExceptDlg.pas. }
{ }
{ The Initial Developer of the Original Code is Petr Vones. }
{ Portions created by Petr Vones are Copyright (C) of Petr Vones. }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: 2011-12-28 22:59:49 +0200 (Τετ, 28 Δεκ 2011) $ }
{ Revision: $Rev:: 3655 $ }
{ Author: $Author:: outchy $ }
{ }
{**************************************************************************************************}
unit dlgExceptionMail;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, AppEvnts, JclSysUtils, JclMapi,
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
JclUnitVersioningProviders,
{$ENDIF UNITVERSIONING}
JclDebug, dlgPyIDEBase, SpTBXItem, SpTBXControls;
const
UM_CREATEDETAILS = WM_USER + $100;
type
TExceptionDialogMail = class(TPyIDEDlgBase)
SendBtn: TSpTBXButton;
TextMemo: TMemo;
OkBtn: TSpTBXButton;
DetailsBtn: TSpTBXButton;
BevelDetails: TBevel;
DetailsMemo: TMemo;
procedure SendBtnClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DetailsBtnClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
private
private
FDetailsVisible: Boolean;
FThreadID: DWORD;
FLastActiveControl: TWinControl;
FNonDetailsHeight: Integer;
FFullHeight: Integer;
WinPlatform: string;
function GetReportAsText: string;
procedure SetDetailsVisible(const Value: Boolean);
procedure UMCreateDetails(var Message: TMessage); message UM_CREATEDETAILS;
protected
procedure AfterCreateDetails; dynamic;
procedure BeforeCreateDetails; dynamic;
procedure CreateDetails; dynamic;
procedure CreateReport;
function ReportMaxColumns: Integer; virtual;
function ReportNewBlockDelimiterChar: Char; virtual;
procedure NextDetailBlock;
procedure UpdateTextMemoScrollbars;
public
procedure CopyReportToClipboard;
class procedure ExceptionHandler(Sender: TObject; E: Exception);
class procedure ExceptionThreadHandler(Thread: TJclDebugThread);
class procedure ShowException(E: TObject; Thread: TJclDebugThread);
property DetailsVisible: Boolean read FDetailsVisible
write SetDetailsVisible;
property ReportAsText: string read GetReportAsText;
end;
TExceptionDialogMailClass = class of TExceptionDialogMail;
var
ExceptionDialogMailClass: TExceptionDialogMailClass = TExceptionDialogMail;
implementation
{$R *.dfm}
uses
ClipBrd, Math,
JclBase, JclFileUtils, JclHookExcept, JclPeImage, JclStrings, JclSysInfo, JclWin32,
uCommonFunctions, PythonEngine, dmCommands, TypInfo, cPyBaseDebugger;
resourcestring
RsAppError = '%s - application error';
RsExceptionClass = 'Exception class: %s';
RsExceptionMessage = 'Exception message: %s';
RsExceptionAddr = 'Exception address: %p';
RsStackList = 'Stack list, generated %s';
RsModulesList = 'List of loaded modules:';
RsOSVersion = 'System : %s %s, Version: %d.%d, Build: %x, "%s"';
RsProcessor = 'Processor: %s, %s, %d MHz';
RsMemory = 'Memory: %d; free %d';
RsScreenRes = 'Display : %dx%d pixels, %d bpp';
RsActiveControl = 'Active Controls hierarchy:';
RsThread = 'Thread: %s';
RsMissingVersionInfo = '(no module version info)';
RsUnitVersioningIntro = 'Unit versioning information:';
RsSendBugReportAddress = 'pyscripter@gmail.com';
RsSendBugReportSubject = 'PyScripter Bug Report';
RsNoMailClient = 'No %s mail client is available';
var
ExceptionDialogMail: TExceptionDialogMail;
//============================================================================
// Helper routines
//============================================================================
// SortModulesListByAddressCompare
// sorts module by address
function SortModulesListByAddressCompare(List: TStringList;
Index1, Index2: Integer): Integer;
var
Addr1, Addr2: TJclAddr;
begin
Addr1 := TJclAddr(List.Objects[Index1]);
Addr2 := TJclAddr(List.Objects[Index2]);
if Addr1 > Addr2 then
Result := 1
else if Addr1 < Addr2 then
Result := -1
else
Result := 0;
end;
//============================================================================
// TApplication.HandleException method code hooking for exceptions from DLLs
//============================================================================
// We need to catch the last line of TApplication.HandleException method:
// [...]
// end else
// SysUtils.ShowException(ExceptObject, ExceptAddr);
// end;
procedure HookShowException(ExceptObject: TObject; ExceptAddr: Pointer);
begin
if JclValidateModuleAddress(ExceptAddr)
and (ExceptObject.InstanceSize >= Exception.InstanceSize) then
TExceptionDialogMail.ExceptionHandler(nil, Exception(ExceptObject))
else
SysUtils.ShowException(ExceptObject, ExceptAddr);
end;
//----------------------------------------------------------------------------
function HookTApplicationHandleException: Boolean;
const
CallOffset = $86; // Until D2007
CallOffsetDebug = $94; // Until D2007
CallOffsetWin32 = $7A; // D2009 and newer
CallOffsetWin64 = $95; // DXE2 for Win64
type
PCALLInstruction = ^TCALLInstruction;
TCALLInstruction = packed record
Call: Byte;
Address: Integer;
end;
var
TApplicationHandleExceptionAddr, SysUtilsShowExceptionAddr: Pointer;
CALLInstruction: TCALLInstruction;
CallAddress: Pointer;
WrittenBytes: Cardinal;
function CheckAddressForOffset(Offset: Cardinal): Boolean;
begin
try
CallAddress := Pointer(TJclAddr(TApplicationHandleExceptionAddr) + Offset);
CALLInstruction.Call := $E8;
Result := PCALLInstruction(CallAddress)^.Call = CALLInstruction.Call;
if Result then
begin
if IsCompiledWithPackages then
Result := PeMapImgResolvePackageThunk(Pointer(SizeInt(CallAddress) + Integer(PCALLInstruction(CallAddress)^.Address) + SizeOf(CALLInstruction))) = SysUtilsShowExceptionAddr
else
Result := PCALLInstruction(CallAddress)^.Address = SizeInt(SysUtilsShowExceptionAddr) - SizeInt(CallAddress) - SizeOf(CALLInstruction);
end;
except
Result := False;
end;
end;
begin
TApplicationHandleExceptionAddr := PeMapImgResolvePackageThunk(@TApplication.HandleException);
SysUtilsShowExceptionAddr := PeMapImgResolvePackageThunk(@SysUtils.ShowException);
if Assigned(TApplicationHandleExceptionAddr) and Assigned(SysUtilsShowExceptionAddr) then
begin
Result := CheckAddressForOffset(CallOffset) or CheckAddressForOffset(CallOffsetDebug) or
CheckAddressForOffset(CallOffsetWin32) or CheckAddressForOffset(CallOffsetWin64);
if Result then
begin
CALLInstruction.Address := SizeInt(@HookShowException) - SizeInt(CallAddress) - SizeOf(CALLInstruction);
Result := WriteProtectedMemory(CallAddress, @CallInstruction, SizeOf(CallInstruction), WrittenBytes);
end;
end
else
Result := False;
end;
//============================================================================
// Exception dialog
//============================================================================
var
ExceptionShowing: Boolean;
//=== { TExceptionDialogMail } ===============================================
procedure TExceptionDialogMail.AfterCreateDetails;
begin
SendBtn.Enabled := True;
end;
//----------------------------------------------------------------------------
procedure TExceptionDialogMail.BeforeCreateDetails;
begin
SendBtn.Enabled := False;
end;
//----------------------------------------------------------------------------
function TExceptionDialogMail.ReportMaxColumns: Integer;
begin
Result := 78;
end;
//----------------------------------------------------------------------------
procedure TExceptionDialogMail.SendBtnClick(Sender: TObject);
begin
with TJclEmail.Create do
try
ParentWnd := Application.Handle;
Recipients.Add(AnsiString(RsSendBugReportAddress));
Subject := AnsiString(RsSendBugReportSubject);
Body := AnsiString(ReportAsText);
SaveTaskWindows;
if AnyClientInstalled then
try
Send(True);
finally
RestoreTaskWindows;
end
else
ShowMessage(Format(RsNoMailClient, [WinPlatform]));
finally
Free;
end;
end;
//----------------------------------------------------------------------------
procedure TExceptionDialogMail.CopyReportToClipboard;
begin
ClipBoard.AsText := ReportAsText;
end;
//----------------------------------------------------------------------------
procedure TExceptionDialogMail.CreateDetails;
begin
Screen.Cursor := crHourGlass;
DetailsMemo.Lines.BeginUpdate;
try
CreateReport;
DetailsMemo.SelStart := 0;
SendMessage(DetailsMemo.Handle, EM_SCROLLCARET, 0, 0);
AfterCreateDetails;
finally
DetailsMemo.Lines.EndUpdate;
OkBtn.Enabled := True;
DetailsBtn.Enabled := True;
OkBtn.SetFocus;
Screen.Cursor := crDefault;
end;
end;
//----------------------------------------------------------------------------
procedure TExceptionDialogMail.CreateReport;
var
SL: TStringList;
I: Integer;
ModuleName: TFileName;
NtHeaders32: PImageNtHeaders32;
NtHeaders64: PImageNtHeaders64;
ModuleBase: TJclAddr;
ImageBaseStr: string;
C: TWinControl;
CpuInfo: TCpuInfo;
ProcessorDetails: string;
StackList: TJclStackInfoList;
PETarget: TJclPeTarget;
{$IFDEF UNITVERSIONING}
UnitVersioning: TUnitVersioning;
UnitVersioningModule: TUnitVersioningModule;
UnitVersion: TUnitVersion;
ModuleIndex, UnitIndex: Integer;
{$ENDIF UNITVERSIONING}
begin
SL := TStringList.Create;
try
// Version Info
DetailsMemo.Lines.Add(Format('%s version : %s %s', [Application.Title,
ApplicationVersion, WinPlatform]));
DetailsMemo.Lines.Add(Format('Python DLL : %s', [GetPythonEngine.DllName]));
DetailsMemo.Lines.Add(Format('Python Engine : %s',
[GetEnumName(System.TypeInfo(TPythonEngineType),
ord(CommandsDataModule.PyIDEOptions.PythonEngineType))]));
NextDetailBlock;
// Stack list
StackList := JclGetExceptStackList(FThreadID);
if Assigned(StackList) then
begin
DetailsMemo.Lines.Add(Format(LoadResString(PResStringRec(@RsStackList)),
[DateTimeToStr(StackList.TimeStamp)]));
StackList.AddToStrings(DetailsMemo.Lines, True, True, True, True);
NextDetailBlock;
end;
// System and OS information
DetailsMemo.Lines.Add(Format(RsOSVersion, [GetWindowsVersionString, NtProductTypeString,
Win32MajorVersion, Win32MinorVersion, Win32BuildNumber, Win32CSDVersion]));
GetCpuInfo(CpuInfo);
ProcessorDetails := Format(RsProcessor, [CpuInfo.Manufacturer, CpuInfo.CpuName,
RoundFrequency(CpuInfo.FrequencyInfo.NormFreq)]);
if not CpuInfo.IsFDIVOK then
ProcessorDetails := ProcessorDetails + ' [FDIV Bug]';
if CpuInfo.ExMMX then
ProcessorDetails := ProcessorDetails + ' MMXex';
if CpuInfo.MMX then
ProcessorDetails := ProcessorDetails + ' MMX';
if sse in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE';
if sse2 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE2';
if sse3 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE3';
if ssse3 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSSE3';
if sse41 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE41';
if sse42 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE42';
if sse4A in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE4A';
if sse5 in CpuInfo.SSE then
ProcessorDetails := ProcessorDetails + ' SSE5';
if CpuInfo.Ex3DNow then
ProcessorDetails := ProcessorDetails + ' 3DNow!ex';
if CpuInfo._3DNow then
ProcessorDetails := ProcessorDetails + ' 3DNow!';
if CpuInfo.Is64Bits then
ProcessorDetails := ProcessorDetails + ' 64 bits';
if CpuInfo.DEPCapable then
ProcessorDetails := ProcessorDetails + ' DEP';
DetailsMemo.Lines.Add(ProcessorDetails);
DetailsMemo.Lines.Add(Format(RsMemory, [GetTotalPhysicalMemory div 1024 div 1024,
GetFreePhysicalMemory div 1024 div 1024]));
DetailsMemo.Lines.Add(Format(RsScreenRes, [Screen.Width, Screen.Height, GetBPP]));
NextDetailBlock;
// Modules list
if LoadedModulesList(SL, GetCurrentProcessId) then
begin
{$IFDEF UNITVERSIONING}
UnitVersioning := GetUnitVersioning;
UnitVersioning.RegisterProvider(TJclDefaultUnitVersioningProvider);
{$ENDIF UNITVERSIONING}
DetailsMemo.Lines.Add(RsModulesList);
SL.CustomSort(SortModulesListByAddressCompare);
for I := 0 to SL.Count - 1 do
begin
ModuleName := SL[I];
ModuleBase := TJclAddr(SL.Objects[I]);
DetailsMemo.Lines.Add(Format('[%.8x] %s', [ModuleBase, ModuleName]));
PETarget := PeMapImgTarget(Pointer(ModuleBase));
NtHeaders32 := nil;
NtHeaders64 := nil;
if PETarget = taWin32 then
NtHeaders32 := PeMapImgNtHeaders32(Pointer(ModuleBase))
else
if PETarget = taWin64 then
NtHeaders64 := PeMapImgNtHeaders64(Pointer(ModuleBase));
if (NtHeaders32 <> nil) and (NtHeaders32^.OptionalHeader.ImageBase <> ModuleBase) then
ImageBaseStr := Format('<%.8x> ', [NtHeaders32^.OptionalHeader.ImageBase])
else
if (NtHeaders64 <> nil) and (NtHeaders64^.OptionalHeader.ImageBase <> ModuleBase) then
ImageBaseStr := Format('<%.8x> ', [NtHeaders64^.OptionalHeader.ImageBase])
else
ImageBaseStr := StrRepeat(' ', 11);
if VersionResourceAvailable(ModuleName) then
with TJclFileVersionInfo.Create(ModuleName) do
try
DetailsMemo.Lines.Add(ImageBaseStr + BinFileVersion + ' - ' + FileVersion);
if FileDescription <> '' then
DetailsMemo.Lines.Add(StrRepeat(' ', 11) + FileDescription);
finally
Free;
end
else
DetailsMemo.Lines.Add(ImageBaseStr + RsMissingVersionInfo);
{$IFDEF UNITVERSIONING}
for ModuleIndex := 0 to UnitVersioning.ModuleCount - 1 do
begin
UnitVersioningModule := UnitVersioning.Modules[ModuleIndex];
if UnitVersioningModule.Instance = ModuleBase then
begin
if UnitVersioningModule.Count > 0 then
DetailsMemo.Lines.Add(StrRepeat(' ', 11) + LoadResString(PResStringRec(@RsUnitVersioningIntro)));
for UnitIndex := 0 to UnitVersioningModule.Count - 1 do
begin
UnitVersion := UnitVersioningModule.Items[UnitIndex];
DetailsMemo.Lines.Add(Format('%s%s %s %s %s', [StrRepeat(' ', 13), UnitVersion.LogPath, UnitVersion.RCSfile, UnitVersion.Revision, UnitVersion.Date]));
end;
end;
end;
{$ENDIF UNITVERSIONING}
end;
NextDetailBlock;
end;
// Active controls
if (FLastActiveControl <> nil) then
begin
DetailsMemo.Lines.Add(RsActiveControl);
C := FLastActiveControl;
while C <> nil do
begin
DetailsMemo.Lines.Add(Format('%s "%s"', [C.ClassName, C.Name]));
C := C.Parent;
end;
NextDetailBlock;
end;
finally
SL.Free;
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.DetailsBtnClick(Sender: TObject);
begin
DetailsVisible := not DetailsVisible;
end;
//--------------------------------------------------------------------------------------------------
class procedure TExceptionDialogMail.ExceptionHandler(Sender: TObject; E: Exception);
begin
if Assigned(E) then
if ExceptionShowing then
Application.ShowException(E)
else
begin
ExceptionShowing := True;
try
if IsIgnoredException(E.ClassType) then
Application.ShowException(E)
else
ShowException(E, nil);
finally
ExceptionShowing := False;
end;
end;
end;
//--------------------------------------------------------------------------------------------------
class procedure TExceptionDialogMail.ExceptionThreadHandler(Thread: TJclDebugThread);
var
E: Exception;
begin
E := Exception(Thread.SyncException);
if Assigned(E) then
if ExceptionShowing then
Application.ShowException(E)
else
begin
ExceptionShowing := True;
try
if IsIgnoredException(E.ClassType) then
Application.ShowException(E)
else
ShowException(E, Thread);
finally
ExceptionShowing := False;
end;
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormCreate(Sender: TObject);
begin
inherited;
FFullHeight := ClientHeight;
DetailsVisible := False;
Caption := Format(RsAppError, [Application.Title]);
{$IFDEF WIN64}
winplatform := 'x64';
{$ELSE}
winplatform := 'x86';
{$ENDIF}
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormDestroy(Sender: TObject);
begin
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = Ord('C')) and (ssCtrl in Shift) then
begin
CopyReportToClipboard;
MessageBeep(MB_OK);
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormPaint(Sender: TObject);
begin
DrawIcon(Canvas.Handle, TextMemo.Left - GetSystemMetrics(SM_CXICON) - 15,
TextMemo.Top, LoadIcon(0, IDI_ERROR));
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormResize(Sender: TObject);
begin
UpdateTextMemoScrollbars;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.FormShow(Sender: TObject);
begin
BeforeCreateDetails;
MessageBeep(MB_ICONERROR);
if (GetCurrentThreadId = MainThreadID) and (GetWindowThreadProcessId(Handle, nil) = MainThreadID) then
PostMessage(Handle, UM_CREATEDETAILS, 0, 0)
else
CreateReport;
end;
//--------------------------------------------------------------------------------------------------
function TExceptionDialogMail.GetReportAsText: string;
begin
Result := StrEnsureSuffix(NativeCrLf, TextMemo.Text) + NativeCrLf + DetailsMemo.Text;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.NextDetailBlock;
begin
DetailsMemo.Lines.Add(StrRepeat(ReportNewBlockDelimiterChar, ReportMaxColumns));
end;
//--------------------------------------------------------------------------------------------------
function TExceptionDialogMail.ReportNewBlockDelimiterChar: Char;
begin
Result := '-';
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.SetDetailsVisible(const Value: Boolean);
const
DirectionChars: array [0..1] of Char = ( '<', '>' );
var
DetailsCaption: string;
begin
FDetailsVisible := Value;
DetailsCaption := Trim(StrRemoveChars(DetailsBtn.Caption, DirectionChars));
if Value then
begin
Constraints.MinHeight := FNonDetailsHeight + 100;
Constraints.MaxHeight := Screen.Height;
DetailsCaption := '<< ' + DetailsCaption;
ClientHeight := FFullHeight;
DetailsMemo.Height := FFullHeight - DetailsMemo.Top - 3;
end
else
begin
FFullHeight := ClientHeight;
DetailsCaption := DetailsCaption + ' >>';
if FNonDetailsHeight = 0 then
begin
ClientHeight := BevelDetails.Top;
FNonDetailsHeight := Height;
end
else
Height := FNonDetailsHeight;
Constraints.MinHeight := FNonDetailsHeight;
Constraints.MaxHeight := FNonDetailsHeight
end;
DetailsBtn.Caption := DetailsCaption;
DetailsMemo.Enabled := Value;
end;
//--------------------------------------------------------------------------------------------------
class procedure TExceptionDialogMail.ShowException(E: TObject; Thread: TJclDebugThread);
begin
if ExceptionDialogMail = nil then
ExceptionDialogMail := ExceptionDialogMailClass.Create(Application);
try
with ExceptionDialogMail do
begin
if Assigned(Thread) then
FThreadID := Thread.ThreadID
else
FThreadID := MainThreadID;
FLastActiveControl := Screen.ActiveControl;
if E is Exception then
TextMemo.Text := AdjustLineBreaks(StrEnsureSuffix('.', Exception(E).Message))
else
TextMemo.Text := AdjustLineBreaks(StrEnsureSuffix('.', E.ClassName));
UpdateTextMemoScrollbars;
DetailsMemo.Lines.Add(Format(RsExceptionClass, [E.ClassName]));
if E is Exception then
DetailsMemo.Lines.Add(Format(RsExceptionMessage, [StrEnsureSuffix('.', Exception(E).Message)]));
if Thread = nil then
DetailsMemo.Lines.Add(Format(RsExceptionAddr, [ExceptAddr]))
else
DetailsMemo.Lines.Add(Format(RsThread, [Thread.ThreadInfo]));
NextDetailBlock;
ShowModal;
end;
finally
FreeAndNil(ExceptionDialogMail);
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.UMCreateDetails(var Message: TMessage);
begin
Update;
CreateDetails;
end;
//--------------------------------------------------------------------------------------------------
procedure TExceptionDialogMail.UpdateTextMemoScrollbars;
begin
Canvas.Font := TextMemo.Font;
if TextMemo.Lines.Count * Canvas.TextHeight('Wg') > TextMemo.ClientHeight then
TextMemo.ScrollBars := ssVertical
else
TextMemo.ScrollBars := ssNone;
end;
//==================================================================================================
// Exception handler initialization code
//==================================================================================================
var
AppEvents: TApplicationEvents = nil;
procedure InitializeHandler;
begin
if AppEvents = nil then
begin
AppEvents := TApplicationEvents.Create(nil);
AppEvents.OnException := TExceptionDialogMail.ExceptionHandler;
JclStackTrackingOptions := JclStackTrackingOptions + [stRawMode];
JclStackTrackingOptions := JclStackTrackingOptions + [stStaticModuleList];
JclStackTrackingOptions := JclStackTrackingOptions + [stDelayedTrace];
JclDebugThreadList.OnSyncException := TExceptionDialogMail.ExceptionThreadHandler;
JclStartExceptionTracking;
if HookTApplicationHandleException then
JclTrackExceptionsFromLibraries;
end;
end;
//--------------------------------------------------------------------------------------------------
procedure UnInitializeHandler;
begin
if AppEvents <> nil then
begin
FreeAndNil(AppEvents);
JclDebugThreadList.OnSyncException := nil;
JclUnhookExceptions;
JclStopExceptionTracking;
end;
end;
//--------------------------------------------------------------------------------------------------
initialization
InitializeHandler;
finalization
UnInitializeHandler;
end.