-
Notifications
You must be signed in to change notification settings - Fork 1
/
VCEdit.pas
301 lines (273 loc) · 7.98 KB
/
VCEdit.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
{ **************************************************************
Package: XWB - Kernel RPCBroker
Date Created: Sept 18, 1997 (Version 1.1)
Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
Developers: Danila Manapsal, Don Craven, Joel Ivey
Description: Verify Code edit dialog.
Current Release: Version 1.1 Patch 40 (January 7, 2005))
*************************************************************** }
unit VCEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons,
{Broker units}
Trpcb, Hash;
type
TVCEdit = class(TComponent)
private
FRPCBroker : TRPCBroker;
FOldVC : string;
FConfirmFailCnt : integer; //counts failed confirms.
FHelp : string;
FOldVCSet: Boolean; // Shows whether old code was passed in, even if NULL
procedure NoChange(reason : string);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ChangeVCKnowOldVC(strOldVC : string) : Boolean;
function ChangeVC : Boolean;
published
property RPCBroker : TRPCBroker read FRPCBroker write FRPCBroker;
end;
TfrmVCEdit = class(TForm)
lblOldVC: TLabel;
lblNewVC: TLabel;
lblConfirmVC: TLabel;
edtOldVC: TEdit;
edtNewVC: TEdit;
edtConfirmVC: TEdit;
btnOK: TBitBtn;
btnCancel: TBitBtn;
btnHelp: TBitBtn;
procedure btnOKClick(Sender: TObject);
procedure btnHelpClick(Sender: TObject);
procedure edtNewVCExit(Sender: TObject);
procedure edtOldVCChange(Sender: TObject);
protected
{ Private declarations }
FVCEdit : TVCEdit; //Links form to instance of VCEdit.
public
{ Public declarations }
end;
function ChangeVerify(RPCBroker: TRPCBroker): Boolean;
function SilentChangeVerify(RPCBroker: TRPCBroker; OldVerify, NewVerify1, NewVerify2: String; var Reason: String): Boolean;
var
frmVCEdit: TfrmVCEdit;
const
MAX_CONFIRM_FAIL : integer = 3;
U = '^';
{procedure Register;}
implementation
{$R *.DFM}
function ChangeVerify(RPCBroker: TRPCBroker): Boolean;
var
VCEdit1: TVCEdit;
begin
// Str := '';
VCEdit1 := TVCEdit.Create(Application);
try
VCEdit1.RPCBroker := RPCBroker;
if VCEdit1.ChangeVC then //invoke VCEdit form. //VC changed.
Result := True
else
Result := False;
finally
VCEdit1.Free;
end;
end;
function SilentChangeVerify(RPCBroker: TRPCBroker; OldVerify, NewVerify1, NewVerify2: String; var Reason: String): Boolean;
var
OrigContext: String;
begin
Result := False;
Reason := '';
if UpperCase(OldVerify) = UpperCase(NewVerify1) then
Reason := 'The new code is the same as the current one.'
else
if UpperCase(NewVerify1) <> UpperCase(NewVerify2) then
Reason := 'The confirmation code does not match.';
if Reason = '' then
try
with RPCBroker do
begin
OrigContext := CurrentContext;
CreateContext('XUS SIGNON');
RemoteProcedure := 'XUS CVC';
Param[0].PType := literal;
Param[0].Value := Encrypt(UpperCase(OldVerify))
+ U + Encrypt(UpperCase(NewVerify1))
+ U + Encrypt(UpperCase(NewVerify2)) ;
Call;
Reason := '';
if Results[0] = '0' then
Result := True
else if Results.Count > 1 then
Reason := Results[1];
CreateContext(OrigContext);
end;
except
on E: Exception do
begin
RPCBroker.RPCBError := E.Message;
if Assigned(RPCBroker.OnRPCBFailure) then
RPCBroker.OnRPCBFailure(RPCBroker)
else if RPCBroker.ShowErrorMsgs = semRaise then
Raise;
end;
end;
end;
{------------------TVCEdit component------------------------------------}
constructor TVCEDit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOldVCSet := False;
end;
destructor TVCEDit.Destroy;
begin
inherited Destroy;
end;
function TVCEdit.ChangeVCKnowOldVC(strOldVC : string) : Boolean;
begin
FOldVC := strOldVC;
FOldVCSet := True;
Result := ChangeVC;
FOldVCSet := False; // set it back to false in case we come in again
end;
{--------------------------ChangeVC function---------------------------}
function TVCEdit.ChangeVC : Boolean;
var
OldHandle: THandle;
begin
Result := False;
try
frmVCEDit := TfrmVCEDit.Create(application);
with frmVCEDit do
begin
FVCEdit := Self; //To link form to VCEdit instance.
if FOldVCSet then //If old VC known, stuff it & disable editing.
begin
edtOldVC.Color := clBtnFace;
edtOldVC.Enabled := False;
edtOldVC.Text := FOldVC;
end{if};
// ShowApplicationAndFocusOK(Application);
OldHandle := GetForegroundWindow;
SetForegroundWindow(frmVCEdit.Handle);
if ShowModal = mrOK then //outcome of form.
Result := True;
SetForegroundWindow(OldHandle);
end{with};
frmVCEDit.Free;
except
on E: Exception do
begin
FRPCBroker.RPCBError := E.Message;
if Assigned(FRPCBroker.OnRPCBFailure) then
FRPCBroker.OnRPCBFailure(FRPCBroker)
else if FRPCBroker.ShowErrorMsgs = semRaise then
Raise;
end;
end{except};
end;
{------------------TVCEdit.NoChange-------------------------------------
-----------Displays error messages when change fails.-------------------}
procedure TVCEdit.NoChange(reason : string);
begin
ShowMessage('Your VERIFY code was not changed.' + #13 +
reason + #13 );
end;
{-------------------------TfrmVCEdit methods-------------------------------}
procedure TfrmVCEdit.btnOKClick(Sender: TObject);
begin
with FVCEdit do
begin
if edtOldVC.Text = edtNewVC.Text then
begin
NoChange('The new code is the same as the current one.');
edtNewVC.Text := '';
edtConfirmVC.Text := '';
edtNewVC.SetFocus;
end
else
if edtNewVC.Text <> edtConfirmVC.Text then
begin
inc(FConfirmFailCnt);
if FConfirmFailCnt > MAX_CONFIRM_FAIL then
begin
edtNewVC.Text := '';
edtConfirmVC.Text := '';
NoChange('The confirmation code does not match.');
edtNewVC.SetFocus;
end
else
begin
edtConfirmVC.text := '';
NoChange('The confirmation code does not match. Try again.');
edtConfirmVC.SetFocus;
end;
end
else
with FRPCBroker do
begin
RemoteProcedure := 'XUS CVC';
Param[0].PType := literal;
Param[0].Value := Encrypt(UpperCase(edtOldVC.Text))
+ U + Encrypt(UpperCase(edtNewVC.Text))
+ U + Encrypt(UpperCase(edtConfirmVC.Text)) ;
Call;
if Results[0] = '0' then
begin
ShowMessage('Your VERIFY CODE has been changed');
ModalResult := mrOK; //Close form.
end
else
begin
if Results.Count > 1 then
NoChange(Results[1])
else
NoChange('');
edtNewVC.Text := '';
edtConfirmVC.Text := '';
edtNewVC.SetFocus;
end;
end;
end{with};
end;
procedure TfrmVCEdit.btnHelpClick(Sender: TObject);
begin
with FVCEdit do
begin
if FHelp = '' then
begin
with FRPCBroker do
begin
RemoteProcedure := 'XUS AV HELP';
Call;
if Results.Count > 0 then
FHelp := Results[0];
FHelp := 'Enter a new verify code and then confirm it.'
+ #13#13 + FHelp;
if FOldVC = '' then
FHelp := 'Enter your current verify code first.' + #13#10 + FHelp;
end{with};
end{if};
ShowMessage(FHelp);
end{with};
end;
procedure TfrmVCEdit.edtNewVCExit(Sender: TObject);
begin
if edtNewVC.Modified then
begin
FVCEdit.FConfirmFailCnt := 0; //Reset counter.
edtNewVC.Modified := False;
end;
end;
procedure TfrmVCEdit.edtOldVCChange(Sender: TObject); //Also NewVC and ConfirmVC
begin
btnOk.Default := ((edtNewVC.Text <> '') and //Update status of OK btn.
(edtOldVC.Text <> '') and
(edtConfirmVC.Text <> '') );
end;
end.