-
Notifications
You must be signed in to change notification settings - Fork 14
/
rpeditaliasclx.pas
366 lines (329 loc) · 8.27 KB
/
rpeditaliasclx.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
{*******************************************************}
{ }
{ Report Manager }
{ }
{ rpeditalias }
{ }
{ }
{ Alias List collection editor for }
{ Delphi 4,5 Builder 4,5 }
{ }
{ Copyright (c) 1994-2019 Toni Martir }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
unit rpeditaliasclx;
interface
{$I rpconf.inc}
uses
SysUtils, Classes, QGraphics, QControls, QForms, QDialogs,
QExtCtrls, QComCtrls, QActnList,rpalias,
Designintf,DesignEditors,
TypInfo,DB,rpdatainfo,
rpeditconn,
ImgList, StdCtrls, QImgList, QStdCtrls;
type
TFRpEditAlias = class(TForm)
ImageList1: TImageList;
ActionList1: TActionList;
ANewParam: TAction;
ADelete: TAction;
ARename: TAction;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton5: TToolButton;
ToolButton4: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
PAliases: TPanel;
PBottom: TPanel;
BOK: TButton;
BCancel: TButton;
LAliases: TListBox;
Splitter1: TSplitter;
Label1: TLabel;
ComboDataset: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ANewParamExecute(Sender: TObject);
procedure LAliasesClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ADeleteExecute(Sender: TObject);
procedure ComboDatasetClick(Sender: TObject);
procedure ARenameExecute(Sender: TObject);
procedure BOKClick(Sender: TObject);
private
{ Private declarations }
rpalias1:TRpAlias;
{$IFNDEF USEVARIANTS}
Designer:IFormDesigner;
{$ENDIF}
{$IFDEF USEVARIANTS}
Designer:IDesigner;
{$ENDIF}
dook:Boolean;
procedure UpdateList;
procedure FillComboDataset;
procedure AddDatasetName(const aname:string);
public
{ Public declarations }
end;
// Property editor for aliases
TRpAliasPropEditor=class(TPropertyEditor)
protected
public
function GetAttributes:TPropertyAttributes;override;
procedure Edit;override;
function GetValue:string;override;
end;
// Property editor for aliases
TRpConnectionPropEditor=class(TPropertyEditor)
protected
public
function GetAttributes:TPropertyAttributes;override;
procedure Edit;override;
function GetValue:string;override;
end;
implementation
{$R *.xfm}
procedure TRpAliasPropEditor.Edit;
var
dia:TFRpEditAlias;
i:integer;
begin
dia:=TFRpEditAlias.Create(Application);
try
dia.Designer:=Designer;
for i:=0 to PropCount-1 do
begin
if (GetComponent(i) Is TRpAlias) then
begin
dia.rpalias1.List.Assign((GetComponent(i) As TRpAlias).List);
dia.rpalias1.Connections.Assign((GetComponent(i) As TRpAlias).Connections);
break;
end;
end;
if (dia.dook) then
begin
for i:=0 to PropCount-1 do
begin
if (GetComponent(i) Is TRpAlias) then
begin
(GetComponent(i) As TRpAlias).List.Assign(dia.rpalias1.List);
(GetComponent(i) As TRpAlias).List.Assign(dia.rpalias1.List);
end;
end;
Modified;
end;
finally
dia.free;
end;
end;
function TRpAliasPropEditor.GetAttributes:TPropertyAttributes;
begin
Result:=[paDialog];
end;
function TRpAliasPropEditor.GetValue:string;
begin
Result:='Dataset aliases';
end;
procedure TRpConnectionPropEditor.Edit;
var
alias1:TRpAlias;
i:integer;
found:Boolean;
begin
alias1:=TRpAlias.Create(Application);
try
found:=false;
for i:=0 to PropCount-1 do
begin
if (GetComponent(i) Is TRpAlias) then
begin
alias1.Connections.Assign((GetComponent(i) As TRpAlias).Connections);
found:=true;
break;
end;
end;
if found then
begin
if ShowModifyConnections(alias1.Connections) then
begin
for i:=0 to PropCount-1 do
begin
if (GetComponent(i) Is TRpAlias) then
begin
(GetComponent(i) As TRpAlias).Connections.Assign(alias1.Connections);
end;
end;
Modified;
end;
end;
finally
alias1.free;
end;
end;
function TRpConnectionPropEditor.GetAttributes:TPropertyAttributes;
begin
Result:=[paDialog];
end;
function TRpConnectionPropEditor.GetValue:string;
begin
Result:='Connection aliases';
end;
procedure TFRpEditAlias.FormCreate(Sender: TObject);
begin
rpalias1:=TRpAlias.Create(Self);
end;
procedure TFRpEditAlias.ANewParamExecute(Sender: TObject);
var
aname:String;
aitem:TRpAliasListItem;
begin
aname:=InputBox('New alias','Alias name','');
aname:=Trim(UpperCase(aname));
if rpalias1.List.indexof(aname)>0 then
Raise Exception.Create('Alias name already exists');
aitem:=rpalias1.List.Add;
aitem.Alias:=aname;
UpdateList;
LAliases.ItemIndex:=LAliases.Items.Count-1;
LAliasesClick(Self);
end;
procedure TFRpEditAlias.UpdateList;
var
i:integer;
begin
LAliases.Clear;
for i:=0 to rpalias1.List.count-1 do
begin
LAliases.Items.Add(rpalias1.List.Items[i].Alias);
end;
end;
procedure TFRpEditAlias.FormShow(Sender: TObject);
begin
// Fills the list with all the available dataset components
FillComboDataset;
PAliases.Visible:=True;
PAliases.Align:=alClient;
FillComboDataset;
UpdateList;
if LAliases.Items.Count>0 then
LAliases.ItemIndex:=0
else
LAliases.ItemIndex:=-1;
LAliasesClick(Self);
end;
procedure TFRpEditAlias.AddDatasetName(const aname:string);
begin
ComboDataset.Items.Add(aname);
end;
procedure TFRpEditAlias.FillComboDataset;
begin
ComboDataset.Items.Clear;
Designer.GetComponentnames(GetTypeData(TypeInfo(TDataSet)),AddDatasetName);
ComboDataset.Items.Insert(0,' ');
end;
procedure TFRpEditAlias.ADeleteExecute(Sender: TObject);
var
oldindex:integer;
begin
if LAliases.Items.Count<1 then
begin
Label1.Visible:=False;
ComboDataset.Visible:=False;
exit;
end;
if LAliases.ItemIndex<0 then
begin
Label1.Visible:=False;
ComboDataset.Visible:=False;
exit;
end;
oldindex:=LAliases.ItemIndex;
rpalias1.List.items[LAliases.itemindex].free;
UpdateList;
dec(oldindex);
if oldindex<0 then
oldindex:=0;
if LAliases.Items.Count>0 then
begin
LAliases.ItemIndex:=oldindex;
LAliasesClick(Self);
end;
end;
procedure TFRpEditAlias.LAliasesClick(Sender: TObject);
var
adataset:TDataset;
begin
ComboDataset.ItemIndex:=0;
// Fills with the values
if LAliases.Items.Count<1 then
begin
Label1.Visible:=False;
ComboDataset.Visible:=False;
exit;
end;
if LAliases.ItemIndex<0 then
begin
Label1.Visible:=False;
ComboDataset.Visible:=False;
exit;
end;
adataset:=rpalias1.List.Items[LAliases.ItemIndex].Dataset;
if adataset=nil then
ComboDataset.ItemIndex:=0
else
begin
ComboDataset.ItemIndex:=ComboDataset.Items.IndexOf(Designer.GetComponentName(adataset));
if ComboDataset.ItemIndex<0 then
ComboDataset.ItemIndex:=0;
end;
Label1.Visible:=True;
ComboDataset.Visible:=True;
end;
procedure TFRpEditAlias.ComboDatasetClick(Sender: TObject);
var
data:TDataSet;
begin
if LAliases.Items.Count<1 then
exit;
if LAliases.ItemIndex<0 then
exit;
if ComboDataset.ItemIndex<1 then
data:=nil
else
begin
data:=Designer.GetComponent(ComboDataset.Text) As TDataSet;
end;
rpalias1.List.Items[LAliases.ItemIndex].Dataset:=data;
end;
procedure TFRpEditAlias.ARenameExecute(Sender: TObject);
var
aname:String;
aitem:TRpAliasListItem;
begin
if LAliases.Items.Count<1 then
exit;
if LAliases.ItemIndex<0 then
exit;
aname:=InputBox('Rename alias','New alias name','');
aname:=Trim(UpperCase(aname));
if rpalias1.List.indexof(aname)>0 then
Raise Exception.Create('Alias name already exists');
aitem:=rpalias1.List.Items[LAliases.ItemIndex];
aitem.Alias:=aname;
UpdateList;
LAliases.ItemIndex:=LAliases.Items.IndexOf(aname);
LAliasesClick(Self);
end;
procedure TFRpEditAlias.BOKClick(Sender: TObject);
begin
dook:=true;
Close;
end;
end.