-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathESoft.Launcher.UI.ParamEditor.pas
204 lines (177 loc) · 6.01 KB
/
ESoft.Launcher.UI.ParamEditor.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
Unit ESoft.Launcher.UI.ParamEditor;
Interface
Uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls,
ESoft.Launcher.DM.Main,
ESoft.Launcher.Parameter;
Type
TFormParamEditor = Class(TForm)
GroupBox1: TGroupBox;
btnCancel: TButton;
btnOK: TButton;
Label5: TLabel;
Label1: TLabel;
edtParameter: TButtonedEdit;
edtParamName: TButtonedEdit;
chkDefaultInclude: TCheckBox;
chkConnectionParam: TCheckBox;
cbConnections: TComboBox;
Label2: TLabel;
cbCategory: TComboBox;
Label7: TLabel;
chkExcludeAdditionalParameters: TCheckBox;
Procedure chkConnectionParamClick(Sender: TObject);
Procedure btnOKClick(Sender: TObject);
Procedure edtParamNameKeyPress(Sender: TObject; Var Key: Char);
Procedure edtParamNameRightButtonClick(Sender: TObject);
Procedure FormActivate(Sender: TObject);
Procedure cbConnectionsExit(Sender: TObject);
procedure cbCategoryKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
Private
// Private declarations. Variables/Methods can be access inside this class and other class in the same unit. { Ajmal }
Strict Private
// Strict Private declarations. Variables/Methods can be access inside this class only. { Ajmal }
FInitialized: Boolean;
FParameter: TEParameterBase;
Public
{ Public declarations }
Constructor Create(aOwner: TComponent; Const aParameter: TEParameterBase = Nil); Reintroduce;
Procedure LoadData(const aParameter: TEParameterBase);
Published
Property Parameter: TEParameterBase Read FParameter;
End;
Var
FormParamEditor: TFormParamEditor;
Implementation
{$R *.dfm}
Uses
UnitMDIMain;
{ TFormParamEditor }
Procedure TFormParamEditor.btnOKClick(Sender: TObject);
Var
iParameterType: Integer;
Begin
cbConnectionsExit(Nil);
If chkConnectionParam.Checked Then
iParameterType := cParamTypeConnection
Else
iParameterType := cParamTypeAdditional;
If Not Assigned(FParameter) Then
Begin
If Trim(edtParamName.Text) = '' Then
Begin
MessageDlg('Name cannot be empty', mtError, [mbOK], 0);
Abort;
End;
FParameter := FormMDIMain.Parameters.AddItem(edtParamName.Text, iParameterType);
End;
Parameter.Name := edtParamName.Text;
Parameter.Parameter := edtParameter.Text;
If chkConnectionParam.Checked Then
Parameter.ParamCategory := cbCategory.Text
Else
Parameter.ParamCategory := '';
Case iParameterType Of
cParamTypeConnection:
Begin
With TEConnectionParameter(FParameter) Do
Begin
Connection := cbConnections.Text;
ExcludeAdditionalParams := chkExcludeAdditionalParameters.Checked;
End;
End;
cParamTypeAdditional:
Begin
TEAdditionalParameter(FParameter).DefaultInclude := chkDefaultInclude.Checked;
End;
End;
Parameter.SaveData;
STDatabase.SaveToDB;
ModalResult := mrOk;
End;
Procedure TFormParamEditor.cbConnectionsExit(Sender: TObject);
Begin
If (cbConnections.Text <> '') And ((cbConnections.Items.IndexOf(cbConnections.Text)) = -1) Then
Begin
MessageDlg('Invalid connection', mtError, [mbOK], 0);
Abort;
End;
End;
procedure TFormParamEditor.cbCategoryKeyPress(Sender: TObject; var Key: Char);
begin
If Not(key In ['A' .. 'Z', 'a' .. 'z', '0' .. '9', '_', ' ', #46, #8]) Then
Abort;
end;
Procedure TFormParamEditor.chkConnectionParamClick(Sender: TObject);
Begin
chkDefaultInclude.Enabled := Not chkConnectionParam.Checked;
chkExcludeAdditionalParameters.Enabled := chkConnectionParam.Checked;
cbConnections.Enabled := chkConnectionParam.Checked;
cbCategory.Enabled := chkConnectionParam.Checked;
End;
Constructor TFormParamEditor.Create(aOwner: TComponent; Const aParameter: TEParameterBase);
Begin
FInitialized := False;
Inherited Create(aOwner);
FParameter := aParameter;
edtParamName.Enabled := Not Assigned(FParameter);
chkConnectionParam.Enabled := edtParamName.Enabled;
End;
Procedure TFormParamEditor.edtParamNameKeyPress(Sender: TObject; Var Key: Char);
Begin
If Not(key In ['A' .. 'Z', 'a' .. 'z', '0' .. '9', '_', ' ', #46, #8]) Then
Abort;
End;
Procedure TFormParamEditor.edtParamNameRightButtonClick(Sender: TObject);
Begin
TButtonedEdit(Sender).Text := '';
End;
Procedure TFormParamEditor.FormActivate(Sender: TObject);
Begin
If Not FInitialized Then
Begin
FInitialized := True;
If Assigned(FParameter) Then
LoadData(FParameter);
End;
End;
procedure TFormParamEditor.FormCreate(Sender: TObject);
begin
cbCategory.Items := FormMDIMain.ParamCategories;
// Reload connections. { Ajmal }
FormMDIMain.Connections.LoadConnections;
cbConnections.Items.AddStrings(FormMDIMain.Connections.Connections);
end;
Procedure TFormParamEditor.LoadData(const aParameter: TEParameterBase);
var
varConnParam: TEConnectionParameter Absolute aParameter;
varAdditionalParam: TEAdditionalParameter Absolute aParameter;
Begin
chkConnectionParamClick(Nil);
edtParamName.Text := aParameter.Name;
edtParameter.Text := aParameter.Parameter;
chkConnectionParam.Checked := aParameter Is TEConnectionParameter;
cbCategory.Text := aParameter.ParamCategory;
If Not chkConnectionParam.Checked Then
Begin
chkDefaultInclude.Checked := varAdditionalParam.DefaultInclude;
chkExcludeAdditionalParameters.Checked := False;
End
Else
Begin
chkExcludeAdditionalParameters.Checked := varConnParam.ExcludeAdditionalParams;
cbConnections.ItemIndex := cbConnections.Items.IndexOf(TEConnectionParameter(aParameter).Connection);
End;
End;
End.