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
|
{%mainunit fpg_dialogs.pas}
{$IFDEF read_interface}
TfpgPromptUserDialog = class(TfpgBaseDialog)
private
lblTitle: TfpgLabel;
lblTitlePw: TfpgLabel;
function GetUserID: TfpgString;
function GetUserPassword: TfpgString;
procedure SetUserID(const AValue: TfpgString);
protected
edUserID: TfpgEdit;
edPassword: TfpgEdit;
procedure btnOKClick(Sender: TObject); override;
public
constructor Create(AOwner: TComponent); override;
// Gof defines this Authenticate method a Hook operation in Template methods pattern.
// Subclass will have to override and implement it. By default it returns True.
function Authenticate: boolean; virtual;
procedure Wiggle(const Seconds: integer = 1; const MovingPixels: integer = 5; const aSleep: integer = 75);
property UserID: TfpgString read GetUserID write SetUserID;
property Password: TfpgString read GetUserPassword;
end;
TfpgPromptUserDbDialog = class(TfpgPromptUserDialog)
private
lblDatabases: TfpgLabel;
protected
aStringList: TStringList;
cbDatabases: TfpgComboBox;
function GetSelectedDatabase: TfpgString; virtual;
procedure PopulateComboDb; virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Database: TfpgString read GetSelectedDatabase;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
{ TfpgPromptUserDialog }
function TfpgPromptUserDialog.GetUserID: TfpgString;
begin
Result := edUserID.Text;
end;
function TfpgPromptUserDialog.GetUserPassword: TfpgString;
begin
Result := edPassword.Text;
end;
procedure TfpgPromptUserDialog.SetUserID(const AValue: TfpgString);
begin
edUserID.Text := AValue;
end;
procedure TfpgPromptUserDialog.btnOKClick(Sender: TObject);
begin
if Authenticate then
inherited btnOKClick(Sender);
end;
constructor TfpgPromptUserDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// reset dimensions
Width := 200;
Height := 140;
MinWidth := 200;
MinHeight := 140;
lblTitle := CreateLabel(self, 8, 8, rsUserName);
edUserID := CreateEdit(self, 8, 28, 184, 0);
edUserID.Anchors := [anLeft, anTop, anRight];
lblTitlePw := CreateLabel(self, 8, 55, rsPassword);
edPassword := CreateEdit(self, 8, 73, 184, 0);
edPassword.Anchors := [anLeft, anTop, anRight];
edPassword.PasswordMode := True;
// reposition buttons
btnCancel.Left := Width-FDefaultButtonWidth-FSpacing;
btnCancel.Top := Height - FSpacing - btnCancel.Height;
btnOK.Left := btnCancel.Left-FDefaultButtonWidth-FSpacing;
btnOK.Top := btnCancel.Top;
// now reset tab order
edUserID.TabOrder := 1;
edPassword.TabOrder := 2;
btnOK.TabOrder := 3;
btnCancel.TabOrder := 4;
end;
function TfpgPromptUserDialog.Authenticate: boolean;
begin
Result := True;
end;
procedure TfpgPromptUserDialog.Wiggle(const Seconds: integer; const MovingPixels: integer; const aSleep: integer);
var
MyTime: TDateTime;
begin
MyTime := Now;
repeat
MoveWindow(Left - MovingPixels, Top);
fpgApplication.ProcessMessages;
Sleep(aSleep);
MoveWindow(Left + MovingPixels * 2, Top);
fpgApplication.ProcessMessages;
Sleep(aSleep);
MoveWindow(Left - MovingPixels, Top);
fpgApplication.ProcessMessages;
until SecondsBetween(Now, MyTime) >= Seconds;
end;
{ TfpgPromptUserDbDialog }
function TfpgPromptUserDbDialog.GetSelectedDatabase: TfpgString;
begin
Result := cbDatabases.Text;
end;
constructor TfpgPromptUserDbDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// reset dimensions
Width := 200;
Height := 185;
MinWidth := 200;
MinHeight := 185;
aStringList := TStringList.Create;
lblDatabases := CreateLabel(self, 8, 101, rsDatabase);
cbDatabases := CreateComboBox(self, 8, 119, 184, aStringList);
cbDatabases.Anchors := [anLeft, anTop, anRight];
cbDatabases.Height := edUserID.Height;
// reposition buttons
btnCancel.Left := Width-FDefaultButtonWidth-FSpacing;
btnCancel.Top := Height - FSpacing - btnCancel.Height;
btnOK.Left := btnCancel.Left-FDefaultButtonWidth-FSpacing;
btnOK.Top := btnCancel.Top;
// now reset tab order
edUserID.TabOrder := 1;
edPassword.TabOrder := 2;
cbDatabases.TabOrder := 3;
btnOK.TabOrder := 5;
btnCancel.TabOrder := 6;
PopulateComboDb;
end;
destructor TfpgPromptUserDbDialog.Destroy;
begin
aStringList.Free;
inherited Destroy;
end;
procedure TfpgPromptUserDbDialog.PopulateComboDb;
begin
// do nothing. Derived classe will implement it
end;
{$ENDIF read_implementation}
|