Menu

[r2337]: / trunk / Src / FmTrappedBugReportDlg.pas  Maximize  Restore  History

Download this file

193 lines (168 with data), 5.6 kB

  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
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2009-2012, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a bug report dialogue box that is displayed when unexpected
* exceptions are detected.
}
unit FmTrappedBugReportDlg;
interface
uses
// Delphi
SysUtils, Classes, ActnList, ExtActns, StdCtrls, Controls, ExtCtrls,
// Project
FmBugReportBaseDlg, UBaseObjects;
type
{
TTrappedBugReportDlg:
Bug report dialog box for display when unexpected exceptions are detected.
}
TTrappedBugReportDlg = class(TBugReportBaseDlg, INoPublicConstruct)
bvlBugDesc: TBevel;
lblBugInfo: TLabel;
lblInstruct1: TLabel;
lblInstruct2: TLabel;
lblInstruct3: TLabel;
lblInstruct4: TLabel;
lblIntro: TLabel;
btnTerminate: TButton;
actTerminate: TAction;
procedure actTerminateExecute(Sender: TObject);
strict private
fErrorObj: Exception; // Reference to exception being reported.
procedure CopyBugInfoToClipboard;
{Places information about the exception, the OS and the program version on
the clipboard ready for pasting into the bug report.
}
strict protected
procedure ConfigForm; override;
{Configures form. Ensures correct font is used in labels and displays
details of exception.
}
procedure ArrangeForm; override;
{Aligns and sizes of controls depending on text sizes.
}
procedure GoToTracker; override;
{Displays online bug tracker after placing info about bug on clipboard.
}
public
class procedure Execute(Owner: TComponent; const ErrorObj: Exception);
{Creates and displays bug report dialog box.
@param Owner [in] Component that owns dialog box. Dialog box is aligned
over this component if it is a form. If Owner it is nil or not a form
the dialog is aligned over the active form.
@param ErrorObj [in] Exception that caused dialog box to be displayed.
}
end;
implementation
uses
// Delphi
Clipbrd, Forms, Windows,
// Project
UAppInfo, UConsts, UCtrlArranger, UFontHelper, UMessageBox, USystemInfo;
{$R *.dfm}
{ TTrappedBugReportDlg }
procedure TTrappedBugReportDlg.actTerminateExecute(Sender: TObject);
{Terminates application only if user confirms.
@param Sender [in] Not used.
}
resourcestring
// Text for custom confirmation dialog box
sTitle = 'Confirm';
sConfirmMsg = 'Please confirm that you want to terminate the application.'
+ EOL2
+ 'CodeSnip will attempt to save any unsaved changes to the database.';
sOKText = 'Terminate';
sCancelText = 'Cancel';
begin
if TMessageBox.Custom(
Self,
sConfirmMsg,
[
TMessageBoxButton.Create(sOKText, mrOK),
TMessageBoxButton.Create(sCancelText, mrCancel, True, True)
],
sTitle,
IDI_QUESTION
) = mrOK then
Application.Terminate;
end;
procedure TTrappedBugReportDlg.ArrangeForm;
{Aligns and sizes of controls depending on text sizes.
}
begin
TCtrlArranger.SetLabelHeights(Self);
bvlBugDesc.Height := lblBugInfo.Height + 12;
bvlBugDesc.Top := TCtrlArranger.BottomOf(lblIntro, 8);
lblBugInfo.Top := bvlBugDesc.Top + 6;
lblInstruct1.Top := TCtrlArranger.BottomOf(bvlBugDesc, 8);
lblInstruct2.Top := TCtrlArranger.BottomOf(lblInstruct1, 6);
lblInstruct3.Top := TCtrlArranger.BottomOf(lblInstruct2, 6);
lblBugTracker.Top := TCtrlArranger.BottomOf(lblInstruct3, 6);
lblInstruct4.Top := TCtrlArranger.BottomOf(lblBugTracker, 12);
inherited;
btnTerminate.Top := btnClose.Top;
TCtrlArranger.MoveToLeftOf(btnClose, btnTerminate, 4);
end;
procedure TTrappedBugReportDlg.ConfigForm;
{Configures form. Ensures correct font is used in labels and displays details
of exception.
}
begin
inherited;
// set required label fonts
TFontHelper.SetDefaultBaseFont(lblIntro.Font, False);
TFontHelper.SetDefaultBaseFont(lblBugInfo.Font, False);
TFontHelper.SetDefaultBaseFont(btnTerminate.Font, False);
// display the exception's message
lblBugInfo.Caption := fErrorObj.Message;
end;
procedure TTrappedBugReportDlg.CopyBugInfoToClipboard;
{Places information about the exception, the OS and the program version on the
clipboard ready for pasting into the bug report.
}
const
// Information template
cBugInfo = '----- BEGIN BUG INFO -----' + EOL
+ 'Version = %0:s' + EOL
+ 'OS = %1:s' + EOL
+ 'Exception = %2:s' + EOL
+ '----- END BUG INFO -----' + EOL2;
begin
Clipboard.AsText := Format(
cBugInfo,
[TAppInfo.ProgramFileVersion, TOSInfo.Description, fErrorObj.Message]
);
end;
class procedure TTrappedBugReportDlg.Execute(Owner: TComponent;
const ErrorObj: Exception);
{Creates and displays bug report dialog box.
@param Owner [in] Component that owns dialog box. Dialog box is aligned
over this component if it is a form. If Owner it is nil or not a form the
dialog is aligned over the active form.
@param ErrorObj [in] Exception that caused dialog box to be displayed.
}
begin
Assert(Assigned(ErrorObj), ClassName + '.Execute: ErrorObj is nil');
with InternalCreate(Owner) do
try
fErrorObj := ErrorObj;
ShowModal;
finally
Free;
end;
end;
procedure TTrappedBugReportDlg.GoToTracker;
{Displays online bug tracker after placing info about bug on clipboard.
}
begin
CopyBugInfoToClipboard;
inherited; // displays tracker
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.