forked from delphidabbler/vied
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFmIdEd.pas
113 lines (92 loc) · 2.52 KB
/
FmIdEd.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
{
* 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) 1998-2014, Peter Johnson (www.delphidabbler.com).
*
* Identifier editor dialogue box. Allows user to enter a valid version
* information resource identifier.
}
unit FmIdEd;
interface
uses
// Delphi
StdCtrls, Controls, ExtCtrls, Classes,
// Project
FmGenericOKDlg;
type
{
TIdEditor:
Class that implements a dialog box that allows user to enter a valid version
information resource identifier.
}
TIdEditor = class(TGenericOKDlg)
lblID: TLabel;
edId: TEdit;
procedure edIdKeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
fIdentifier: string;
{Value of Identifier property}
public
property Identifier: string read fIdentifier write fIdentifier;
{Holds default identifier provided by caller and edited identifier if user
clicks OK}
end;
implementation
uses
// Delphi
SysUtils,
// Project
UHelp, UMsgDlgs;
{$R *.DFM}
{ TIdEditor }
procedure TIdEditor.btnOKClick(Sender: TObject);
{Click event handler for OK button: validates entered identifier and stores
in Identifier property if valid.
@param Sender [in] Not used.
}
begin
inherited;
{Check that entered text doesn't start with digit}
if (edId.Text <> '') and CharInSet(edId.Text[1], ['0'..'9']) then
begin
// Identifier did start with digit - error
MsgInvalidIdentifier;
ModalResult := 0;
edId.SetFocus;
end
else
// Identifier is OK - record it in property
fIdentifier := edID.Text;
end;
procedure TIdEditor.edIdKeyPress(Sender: TObject; var Key: Char);
{Key press event handler for identifier edit box: only accepts valid ID
characters or backspace.
@param Sender [in] Not used.
}
begin
inherited;
if not CharInSet(Key, ['a'..'z', 'A'..'Z', '_', '0'..'9', #8]) then
Key := #0
end;
procedure TIdEditor.FormCreate(Sender: TObject);
{Form creation event handler. Sets help topic}
begin
inherited;
HelpTopic := 'dlg-identifier';
end;
procedure TIdEditor.FormShow(Sender: TObject);
{Event handler called when form is shown: intialises controls.
@param Sender [in] Not used.
}
begin
inherited;
// Display indentifier in edit box and move focus to it
edID.Text := fIdentifier;
edId.SetFocus;
end;
end.