Menu

[r3204]: / branches / experimental / Src / TrunkSrc / FrCodeGenPrefs.pas  Maximize  Restore  History

Download this file

766 lines (693 with data), 25.1 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
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
{
* 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) 2010-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a frame that allows user to set source code generation
* preferences.
* Designed for use as one of the tabs in the Preferences dialogue box.
}
unit FrCodeGenPrefs;
interface
uses
// Delphi
Classes, ActnList, StdCtrls, Controls, ComCtrls, Menus, Buttons,
// 3rd party
LVEx,
// Project
FrPrefsBase, UPreferences, UWarnings;
type
/// <summary>Frame that allows user to set source code generation
/// preferences.</summary>
/// <remarks>Designed for use in preferences dialog box.</remarks>
TCodeGenPrefsFrame = class(TPrefsBaseFrame)
chkWARNEnabled: TCheckBox;
lblSymbol: TLabel;
lblMinCompiler: TLabel;
edSymbol: TEdit;
btnAdd: TButton;
btnDelete: TButton;
btnUpdate: TButton;
alMain: TActionList;
actAdd: TAction;
actUpdate: TAction;
actDelete: TAction;
btnPreview: TButton;
actPreview: TAction;
btnPredefined: TBitBtn;
mnuPreDefCompilers: TPopupMenu;
lblState: TLabel;
edMinCompiler: TEdit;
rbStateOff: TRadioButton;
rbStateOn: TRadioButton;
btnRestoreDefaults: TButton;
actRestoreDefaults: TAction;
/// <summary>Creates new warning from data entered in controls and adds it
/// to warnings list.</summary>
procedure actAddExecute(Sender: TObject);
/// <summary>Enables or disables "Add" action depending on validity of data
/// entered in controls.</summary>
procedure actAddUpdate(Sender: TObject);
/// <summary>Deletes warning selected in list view from warnings list.
/// </summary>
procedure actDeleteExecute(Sender: TObject);
/// <summary>Enables "Delete" action only if an item is selected in list
/// view.</summary>
procedure actDeleteUpdate(Sender: TObject);
/// <summary>Displays a preview of $WARN compiler directives that will be
/// emitted by code generator.</summary>
procedure actPreviewExecute(Sender: TObject);
/// <summary>Enables "Preview" action only if user has specified that $WARN
/// directives will be emitted.</summary>
procedure actPreviewUpdate(Sender: TObject);
/// <summary>Restores default $WARN directives, replacing all directives
/// shown in list view.</summary>
procedure actRestoreDefaultsExecute(Sender: TObject);
/// <summary>Updates warning selected in list view with data entered in
/// controls.</summary>
procedure actUpdateExecute(Sender: TObject);
/// <summary>Enables or disables "Update" action depending on validity of
/// data enterend in controls.</summary>
procedure actUpdateUpdate(Sender: TObject);
/// <summary>Displays menu of predefined compiler versions when
/// "pre-defined" button is clicked.</summary>
procedure btnPredefinedClick(Sender: TObject);
/// <summary>Handles clicks on check box that enables or disables warnings
/// and updates warnings object with state.</summary>
procedure chkWARNEnabledClick(Sender: TObject);
/// <summary>Inhibits non-numerical key presses in Min Compiler edit box.
/// </summary>
procedure edMinCompilerKeyPress(Sender: TObject; var Key: Char);
strict private
var
/// <summary>Stores details of warnings.</summary>
fWarnings: IWarnings;
/// <summary>References dynamically created list view control.</summary>
fLVWarnings: TListViewEx;
/// <summary>Handles clicks on pre-defined compiler menu items. Stores
/// version number of selected compiler in associated edit control.
/// </summary>
procedure PreDefCompilerMenuClick(Sender: TObject);
/// <summary>Handles selection of an item in warnings list view. Copies
/// details of selected warning into controls, ready for editing.</summary>
procedure LVWarningsSelected(Sender: TObject; Item: TListItem;
Selected: Boolean);
/// <summary>Specifies that TWarningListItem is to be used to create new
/// list view items.</summary>
procedure LVWarningsCreateItemClass(Sender: TCustomListView;
var ItemClass: TListItemClass);
/// <summary>Compares two list items, Item1 and Item2, using text contained
/// in row specified Data parameter, recording result of comparison in
/// Compare parameter.</summary>
procedure LVWarningsCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
/// <summary>Returns text of list item LI in column specified by Idx.
/// </summary>
/// <remarks>Idx = 0 returns list item's caption while Idx > 0 returns text
/// of SubItem[Idx-1].</remarks>
function LVColumnText(const LI: TListItem; const Idx: Integer): string;
/// <summary>Dynamically creates list view control and sets required
/// properties.</summary>
procedure CreateLV;
/// <summary>Populates list view with details of warnings.</summary>
procedure PopulateLV;
/// <summary>Adds details of given warning to list view.</summary>
procedure AddWarningToLV(const Warning: TWarning);
/// <summary>Sets given list view item to display and record details of
/// given warning.</summary>
procedure SetLVItem(const LI: TListItem; const Warning: TWarning);
/// <summary>Sorts list view using current sort column and direction.
/// </summary>
/// <remarks>Does nothing if list view hasn't already been sorted.
/// </remarks>
procedure ReSortLV;
/// <summary>Returns given version number formatted as a string.</summary>
function FormatCompilerVer(const Ver: Single): string;
/// <summary>Returns index of list view item associated with warning with
/// given symbol.</summary>
/// <remarks>Returns -1 if warning is not in list.</remarks>
function IndexOfSymbolInLV(const Symbol: string): Integer;
/// <summary>Gets warning symbol entered in edit control.</summary>
/// <param name="Symbol">string [out] Required symbol, trimmed of white
/// space.</param>
/// <returns>Boolean. True if symbol is non-empty string, False if not.
/// </returns>
function GetSymbol(out Symbol: string): Boolean;
/// <summary>Checks if symbol entered in edit control is valid.</summary>
function IsValidSymbol: Boolean;
/// <summary>Gets compiler version entered in edit control.</summary>
/// <param name="Ver">Single [out] Required version number, undefined if
/// not valid.</param>
/// <returns>Boolean. True if version number is valid, False if not.
/// </returns>
function GetCompilerVersion(out Ver: Single): Boolean;
/// <summary>Checks if compiler version entered in edit control is
/// valid.</summary>
function IsValidCompilerVersion: Boolean;
/// <summary>Gets a warning state from radio buttons.</summary>
function GetState: Boolean;
/// <summary>Checks if a warning state has been specified.</summary>
function IsValidState: Boolean;
/// <summary>Populates pre-defined compiler version pop-up menu with menu
/// items.</summary>
procedure PopulatePreDefCompilerMenu;
/// <summary>Selects required switch state in radio buttons.</summary>
procedure SelectSwitchState(const State: Boolean);
/// <summary>Returns warning associated with selected list view item.
/// </summary>
function SelectedWarning: TWarning;
/// <summary>Updates edit controls to reflect properties of warning
/// selected in list view.</summary>
/// <remarks>Nulls edit controls if no warning selected.</remarks>
procedure UpdateControls;
public
/// <summary>Constructs and initiases frame.</summary>
constructor Create(AOwner: TComponent); override;
/// <summary>Records details of warnings from given preferences object and
/// updates controls accordingly.</summary>
/// <remarks>Called when page is activated.</remarks>
procedure Activate(const Prefs: IPreferences); override;
/// <summary>Updates given preferences object with details of warnings as
/// modified by user.</summary>
/// <remarks>Called when page is deactivated.</remarks>
procedure Deactivate(const Prefs: IPreferences); override;
/// <summary>Checks if preference changes require that main window UI is
/// updated.</summary>
/// <remarks>Called when dialog box containing frame is closing. Always
/// returns False because these preferences never affect UI.</remarks>
function UIUpdated: Boolean; override;
/// <summary>Arranges controls on frame.</summary>
/// <remarks>Called after frame has been sized.</remarks>
procedure ArrangeControls; override;
/// <summary>Returns a descriptive name for this frame.</summary>
/// <remarks>Used for display in the tab sheet that contains this frame
/// when displayed in the preferences dialog box.</remarks>
function DisplayName: string; override;
/// <summary>Returns an index number that determines this frame's position
/// in relation to other preferences frames.</summary>
/// <remarks>Used by preferences dialog box to determine ordering of tabs
/// that contain the different preferences frames.</remarks>
class function Index: Byte; override;
end;
implementation
uses
// Delphi
SysUtils, Types,
// Project
FmPreferencesDlg, FmPreviewDlg, IntfCommon, UConsts, UCtrlArranger,
UEncodings, UKeysHelper, UMessageBox, UStrUtils, UUtils;
{$R *.dfm}
type
/// <summary>Custom menu item with additional property to store a compiler
/// version.</summary>
TPreDefCompilerMenuItem = class(TMenuItem)
strict private
var
/// <summary>Value of CompilerVer property</summary>
fCompilerVer: Single;
public
/// <summary>Constructs a menu item will all required properties and event
/// handlers.</summary>
/// <param name="AOwner">TComponent [in] Menu item's owner.</param>
/// <param name="ACaption">string [in] Menu item's caption. Should be name
/// of a compiler.</param>
/// <param name="ACompilerVer">Single [in] Version of compiler named in
/// ACaption</param>
/// <param name="AClickHandler">TNotifyEvent [in] Reference to an event
/// handler for menu item's OnClick event.</param>
constructor Create(AOwner: TComponent; const ACaption: string;
const ACompilerVer: Single; const AClickHandler: TNotifyEvent);
reintroduce;
/// <summary>Version number of compiler whose name is displayed in menu
/// item's caption.</summary>
property CompilerVer: Single read fCompilerVer write fCompilerVer;
end;
type
/// <summary>Custom list item class that adds ability to store a TWarning
/// record with list item.</summary>
TWarningListItem = class(TListItem)
strict private
var
/// <summary>Value of Warning property.</summary>
fWarning: TWarning;
public
/// <summary>Warning associated with list item.</summary>
property Warning: TWarning read fWarning write fWarning;
end;
{ TCodeGenPrefsFrame }
procedure TCodeGenPrefsFrame.actAddExecute(Sender: TObject);
var
W: TWarning; // new warning
Symbol: string; // name of warning's symbol
CompilerVer: Single; // min compiler version that supports warning
begin
// Add new warning from edit controls to fWarnings and list view
GetSymbol(Symbol);
GetCompilerVersion(CompilerVer);
W := TWarning.Create(Symbol, CompilerVer, GetState);
fWarnings.Add(W);
AddWarningToLV(W);
ReSortLV;
// Select new list item and make it visible
fLVWarnings.Selected := fLVWarnings.Items[IndexOfSymbolInLV(Symbol)];
fLVWarnings.Selected.MakeVisible(False);
end;
procedure TCodeGenPrefsFrame.actAddUpdate(Sender: TObject);
var
CanAdd: Boolean; // flag that records whether a warning can be added to list
/// Checks if symbol entered in edit control is a duplicate of an existing
/// symbol in the list view.
function SymbolIsDuplicate: Boolean;
var
Symbol: string; // symbol from edit control
begin
GetSymbol(Symbol);
Result := IndexOfSymbolInLV(Symbol) >= 0;
end;
begin
CanAdd := True;
if not IsValidSymbol then
CanAdd := False
else if SymbolIsDuplicate then
CanAdd := False
else if not IsValidCompilerVersion then
CanAdd := False
else if not IsValidState then
CanAdd := False;
actAdd.Enabled := CanAdd;
end;
procedure TCodeGenPrefsFrame.actDeleteExecute(Sender: TObject);
var
Warning: TWarning; // selected warning
begin
Assert(Assigned(fLVWarnings.Selected),
ClassName + '.actDeleteExecute: No list view item selected');
// Delete selected warning
Warning := SelectedWarning;
fLVWarnings.Selected.Delete;
fWarnings.Delete(Warning);
// Ensure nothing selected in list view and clear edit controls
fLVWarnings.Selected := nil;
UpdateControls;
end;
procedure TCodeGenPrefsFrame.actDeleteUpdate(Sender: TObject);
begin
actDelete.Enabled := Assigned(fLVWarnings.Selected);
end;
procedure TCodeGenPrefsFrame.Activate(const Prefs: IPreferences);
begin
(fWarnings as IAssignable).Assign(Prefs.Warnings);
chkWARNEnabled.Checked := fWarnings.Enabled;
PopulateLV;
end;
procedure TCodeGenPrefsFrame.actPreviewExecute(Sender: TObject);
resourcestring
sCaption = 'Compiler Directives Preview';
begin
TPreviewDlg.Execute(
Self.Owner,
TEncodedData.Create(fWarnings.Render, etUnicode),
dtPlainText,
sCaption
);
end;
procedure TCodeGenPrefsFrame.actPreviewUpdate(Sender: TObject);
begin
actPreview.Enabled := (fLVWarnings.Items.Count > 0)
and chkWARNEnabled.Checked;
end;
procedure TCodeGenPrefsFrame.actRestoreDefaultsExecute(Sender: TObject);
resourcestring
// message displayed in confirmation dialogue box
sConfirmAction = 'Are you sure you want to restore the default directives? '
+ EOL2 + 'All existing custom directives will be lost.';
begin
if not TMessageBox.Confirm(Self, sConfirmAction) then
Exit;
fWarnings := TWarnings.Defaults;
fWarnings.Enabled := chkWARNEnabled.Checked;
PopulateLV;
end;
procedure TCodeGenPrefsFrame.actUpdateExecute(Sender: TObject);
var
NewSymbol: string; // new symbol from edit control
NewCompilerVer: Single; // new compiler version from edit control
NewState: Boolean; // new warning state from radio buttons
SelItem: TListItem; // reference to selected item in list view
OldWarning: TWarning; // warning associated with selected list view item
NewWarning: TWarning; // updated warning
begin
Assert(Assigned(fLVWarnings.Selected),
ClassName + '.actUpdateExecute: no item selected in lvWarnings');
GetSymbol(NewSymbol);
GetCompilerVersion(NewCompilerVer);
NewState := GetState;
SelItem := fLVWarnings.Selected;
OldWarning := SelectedWarning;
NewWarning := TWarning.Create(NewSymbol, NewCompilerVer, NewState);
SetLVItem(SelItem, NewWarning);
ReSortLV;
// we update warnings by deleting old one and adding updated version
fWarnings.Delete(OldWarning);
fWarnings.Add(NewWarning);
// Ensure updated item is still selected in list view and is visible
fLVWarnings.Selected := SelItem;
SelItem.MakeVisible(False);
end;
procedure TCodeGenPrefsFrame.actUpdateUpdate(Sender: TObject);
var
CanUpdate: Boolean; // flag that indicates if a warning can be updated
/// Checks if symbol entered in edit control is a duplicate of an existing
/// symbol in the list view, other than that of the selected warning.
function SymbolIsDuplicate: Boolean;
var
Symbol: string; // symbol entered in edit control
LIIdx: Integer; // index of list item with Symbol as caption
begin
GetSymbol(Symbol);
LIIdx := IndexOfSymbolInLV(Symbol);
Result := (LIIdx >= 0) and (LIIdx <> fLVWarnings.Selected.Index);
end;
begin
CanUpdate := True;
if fLVWarnings.Selected = nil then
CanUpdate := False
else if not IsValidSymbol then
CanUpdate := False
else if SymbolIsDuplicate then
CanUpdate := False
else if not IsValidCompilerVersion then
CanUpdate := False
else if not IsValidState then
CanUpdate := False;
actUpdate.Enabled := CanUpdate;
end;
procedure TCodeGenPrefsFrame.AddWarningToLV(const Warning: TWarning);
var
LI: TListItem; // new list item for warning
begin
LI := fLVWarnings.Items.Add;
SetLVItem(LI, Warning);
end;
procedure TCodeGenPrefsFrame.ArrangeControls;
begin
btnPreview.Left := Width - btnPreview.Width;
fLVWarnings.Width := Width;
TCtrlArranger.AlignVCentres(0, [chkWARNEnabled, btnPreview]);
fLVWarnings.Top := TCtrlArranger.BottomOf([chkWARNEnabled, btnPreview], 8);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf(fLVWarnings, 8),
[lblSymbol, edSymbol]
);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf([lblSymbol, edSymbol], 8),
[lblMinCompiler, edMinCompiler, btnPredefined]
);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf([lblMinCompiler, edMinCompiler, btnPredefined], 8),
[lblState, rbStateOff, rbStateOn]
);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf([lblState, rbStateOff, rbStateOn], 8),
[btnAdd, btnDelete, btnUpdate, btnRestoreDefaults]
);
btnRestoreDefaults.Left :=
fLVWarnings.Left + fLVWarnings.Width - btnRestoreDefaults.Width;
end;
procedure TCodeGenPrefsFrame.btnPredefinedClick(Sender: TObject);
var
PopupPos: TPoint; // place where menu pops up
begin
PopupPos := ClientToScreen(
Point(btnPredefined.Left, btnPredefined.Top + btnPredefined.Height)
);
mnuPreDefCompilers.Popup(PopupPos.X, PopupPos.Y);
end;
procedure TCodeGenPrefsFrame.chkWARNEnabledClick(Sender: TObject);
begin
fWarnings.Enabled := chkWARNEnabled.Checked;
end;
constructor TCodeGenPrefsFrame.Create(AOwner: TComponent);
begin
inherited;
HelpKeyword := 'CodeGenPrefs';
fWarnings := TWarnings.Create;
PopulatePreDefCompilerMenu;
CreateLV;
end;
procedure TCodeGenPrefsFrame.CreateLV;
resourcestring
// column header captions
sSymbolColCaption = 'Symbol';
sMinCompilerColCaption = 'Min. Compiler';
sStateColCaption = 'State';
begin
fLVWarnings := TListViewEx.Create(Self);
with fLVWarnings do
begin
Parent := Self;
Height := 150;
Left := 0;
HideSelection := False;
ReadOnly := True;
RowSelect := True;
TabOrder := 2;
ViewStyle := vsReport;
SortImmediately := False;
with Columns.Add do
begin
Caption := sSymbolColCaption;
Width := 240;
end;
with Columns.Add do
begin
Caption := sMinCompilerColCaption;
Width := 100;
end;
with Columns.Add do
begin
Caption := sStateColCaption;
Width := 50;
end;
OnSelectItem := LVWarningsSelected;
OnCompare := LVWarningsCompare;
OnCreateItemClass := LVWarningsCreateItemClass;
end;
end;
procedure TCodeGenPrefsFrame.Deactivate(const Prefs: IPreferences);
begin
fWarnings.Enabled := chkWARNEnabled.Checked;
Prefs.Warnings := fWarnings;
end;
function TCodeGenPrefsFrame.DisplayName: string;
resourcestring
sDisplayName = 'Code Generation';
begin
Result := sDisplayName;
end;
procedure TCodeGenPrefsFrame.edMinCompilerKeyPress(Sender: TObject;
var Key: Char);
begin
if not IsValidDecimalNumberKey((Sender as TEdit).Text, Key) then
KeyErrorBeep;
end;
function TCodeGenPrefsFrame.FormatCompilerVer(const Ver: Single): string;
begin
Result := Format('%.2f', [Ver]);
end;
function TCodeGenPrefsFrame.GetCompilerVersion(out Ver: Single): Boolean;
var
ExtVer: Extended; // version number as Extended float
begin
Result := TryStrToFloat(StrTrim(edMinCompiler.Text), ExtVer);
if Result then
Ver := ExtVer;
end;
function TCodeGenPrefsFrame.GetState: Boolean;
begin
// Only valid iff one radio button is checked
Result := rbStateOn.Checked;
end;
function TCodeGenPrefsFrame.GetSymbol(out Symbol: string): Boolean;
begin
Symbol := StrTrim(edSymbol.Text);
Result := Symbol <> '';
end;
class function TCodeGenPrefsFrame.Index: Byte;
begin
Result := 15;
end;
function TCodeGenPrefsFrame.IndexOfSymbolInLV(const Symbol: string): Integer;
var
LI: TListItem; // each list item in list view
begin
for LI in fLVWarnings.Items do
begin
if StrSameText(Symbol, LI.Caption) then
Exit(LI.Index);
end;
Result := -1;
end;
function TCodeGenPrefsFrame.IsValidCompilerVersion: Boolean;
var
Ver: Single; // compiler version from edit control
begin
Result := GetCompilerVersion(Ver);
if Result then
Result := Ver >= TWarning.MinSupportedCompiler;
end;
function TCodeGenPrefsFrame.IsValidState: Boolean;
begin
Result := rbStateOff.Checked <> rbStateOn.Checked;
end;
function TCodeGenPrefsFrame.IsValidSymbol: Boolean;
var
Symbol: string; // stores symbol: unused
begin
Result := GetSymbol(Symbol);
end;
function TCodeGenPrefsFrame.LVColumnText(const LI: TListItem;
const Idx: Integer): string;
begin
if Idx = 0 then
Result := LI.Caption
else
Result := LI.SubItems[Idx - 1];
end;
procedure TCodeGenPrefsFrame.LVWarningsCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
Compare := StrCompareText(
LVColumnText(Item1, Data + 1), LVColumnText(Item2, Data + 1)
);
if fLVWarnings.SortOrder = soDown then
Compare := -Compare;
end;
procedure TCodeGenPrefsFrame.LVWarningsCreateItemClass(Sender: TCustomListView;
var ItemClass: TListItemClass);
begin
ItemClass := TWarningListItem;
end;
procedure TCodeGenPrefsFrame.LVWarningsSelected(Sender: TObject;
Item: TListItem; Selected: Boolean);
begin
if Selected and Assigned(fLVWarnings.Selected) then
UpdateControls;
end;
procedure TCodeGenPrefsFrame.PopulateLV;
var
W: TWarning; // references each warning
begin
fLVWarnings.Items.BeginUpdate;
try
fLVWarnings.Clear;
for W in fWarnings do
AddWarningToLV(W);
fLVWarnings.Selected := nil;
ReSortLV;
finally
fLVWarnings.Items.EndUpdate;
end;
UpdateControls;
end;
procedure TCodeGenPrefsFrame.PopulatePreDefCompilerMenu;
/// Adds a menu item for given compiler name and version to the pop-up menu.
procedure AddMenuItem(const Compiler: string; const Ver: Single);
begin
mnuPreDefCompilers.Items.Add(
TPreDefCompilerMenuItem.Create(
mnuPreDefCompilers, Compiler, Ver, PreDefCompilerMenuClick
)
);
end;
begin
AddMenuItem('Delphi 6', 14.0);
AddMenuItem('Delphi 7', 15.0);
AddMenuItem('Delphi 2005', 17.0);
AddMenuItem('Delphi 2006', 18.0);
AddMenuItem('Delphi 2007 (Win 32)', 18.5);
AddMenuItem('Delphi 2009', 20.0);
AddMenuItem('Delphi 2010', 21.0);
AddMenuItem('Delphi XE', 22.0);
AddMenuItem('Delphi XE2', 23.0);
AddMenuItem('Delphi XE3', 24.0);
AddMenuItem('Delphi XE4', 25.0);
end;
procedure TCodeGenPrefsFrame.PreDefCompilerMenuClick(Sender: TObject);
begin
edMinCompiler.Text := FormatCompilerVer(
(Sender as TPreDefCompilerMenuItem).CompilerVer
);
end;
procedure TCodeGenPrefsFrame.ReSortLV;
begin
if fLVWarnings.SortColumn <> -1 then
fLVWarnings.CustomSort(nil, fLVWarnings.SortColumn - 1);
end;
function TCodeGenPrefsFrame.SelectedWarning: TWarning;
begin
Assert(Assigned(fLVWarnings.Selected),
ClassName + '.SelectedWarning: No warning selected in list view');
Result := (fLVWarnings.Selected as TWarningListItem).Warning;
end;
procedure TCodeGenPrefsFrame.SelectSwitchState(const State: Boolean);
begin
if State then
rbStateOn.Checked := True
else
rbStateOff.Checked := True;
end;
procedure TCodeGenPrefsFrame.SetLVItem(const LI: TListItem;
const Warning: TWarning);
resourcestring
sOn = 'On';
sOff = 'Off';
const
// Map of warning state onto description
StateDescs: array[Boolean] of string = (sOff, sOn);
begin
LI.Caption := Warning.Symbol;
while LI.SubItems.Count < 2 do
LI.SubItems.Add('');
LI.SubItems[0] := FormatCompilerVer(Warning.MinCompiler);
LI.SubItems[1] := StateDescs[Warning.State];
(LI as TWarningListItem).Warning := Warning;
end;
function TCodeGenPrefsFrame.UIUpdated: Boolean;
begin
Result := False;
end;
procedure TCodeGenPrefsFrame.UpdateControls;
begin
if Assigned(fLVWarnings.Selected) then
begin
edSymbol.Text := SelectedWarning.Symbol;
edMinCompiler.Text := FormatCompilerVer(SelectedWarning.MinCompiler);
SelectSwitchState(SelectedWarning.State);
end
else
begin
edSymbol.Text := '';
edMinCompiler.Text := '';
rbStateOff.Checked := True;
end;
end;
{ TPreDefCompilerMenuItem }
constructor TPreDefCompilerMenuItem.Create(AOwner: TComponent;
const ACaption: string; const ACompilerVer: Single;
const AClickHandler: TNotifyEvent);
begin
inherited Create(AOwner);
Caption := ACaption;
CompilerVer := ACompilerVer;
OnClick := AClickHandler;
end;
initialization
// Register frame with preferences dialog box
TPreferencesDlg.RegisterPage(TCodeGenPrefsFrame);
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.