source: cprs/trunk/BDK50/BDK32_P50/Source/RpcConf1.pas@ 1679

Last change on this file since 1679 was 1678, checked in by healthsevak, 10 years ago

Added this new version of Broker component libraries while updating the working copy to CPRS version 28

File size: 9.0 KB
RevLine 
[1678]1{ **************************************************************
2 Package: XWB - Kernel RPCBroker
3 Date Created: Sept 18, 1997 (Version 1.1)
4 Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
5 Developers: Danila Manapsal, Raul Mendoza, Joel Ivey
6 Description: Server selection dialog.
7 Current Release: Version 1.1 Patch 47 (Jun. 17, 2008))
8*************************************************************** }
9
10{**************************************************
11 p13 - added an OnDestroy event to release the
12 help file. - REM (4/25/00)
13**************************************************}
14unit Rpcconf1;
15
16interface
17
18uses
19 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
20 Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Xwbut1,
21 WinSock, rpcnet, MFunStr;
22
23type
24 TrpcConfig = class(TForm)
25 cboServer: TComboBox;
26 Panel2: TPanel;
27 Panel3: TPanel;
28 pnlPort: TPanel;
29 btnOk: TBitBtn;
30 btnCancel: TBitBtn;
31 Panel1: TPanel;
32 Panel4: TPanel;
33 btnHelp: TBitBtn;
34 btnNew: TButton;
35 procedure cboServerClick(Sender: TObject);
36 procedure FormClose(Sender: TObject; var Action: TCloseAction);
37 procedure FormCreate(Sender: TObject);
38 procedure btnOkClick(Sender: TObject);
39 procedure butCancelClick(Sender: TObject);
40 procedure FormDestroy(Sender: TObject);
41 procedure cboServerExit(Sender: TObject);
42 procedure btnNewClick(Sender: TObject);
43 procedure btnDeleteClick(Sender: TObject);
44
45 private
46 { Private declarations }
47 OrigHelp : String; //Help filename of calling application.
48
49 public
50 { Public declarations }
51 ServerPairs : TStringList;
52 end;
53
54function GetServerInfo(var Server,Port: string): integer;
55function GetServerIP(ServerName: String): String;
56
57var
58 rpcConfig: TrpcConfig;
59 ButtonStatus, Instance: integer;
60 rServer, rPort: string;
61 TaskInstance: integer;
62
63implementation
64
65uses AddServer;
66
67{$R *.DFM}
68
69
70function IsIPAddress(Val: String): Boolean;
71var
72 I: Integer;
73 C: Char;
74begin
75 Result := True;
76 for I := 1 to Length(Val) do // Iterate
77 begin
78 C := Val[I];
79 if not (C in ['0','1','2','3','4','5','6','7','8','9','.']) then
80 begin
81 Result := False;
82 Break;
83 end;
84 end; // for
85end;
86
87{: Library function to obtain an IP address, given a server name }
88function GetServerIP(ServerName: String): String;
89var
90 host,outcome: PChar;
91begin
92 TaskInstance := LibOpen;
93 if not IsIPAddress(ServerName) then
94 begin
95 outcome := StrAlloc(256);
96 host := StrAlloc(length(ServerName) + 1);
97 StrPCopy(host, ServerName);
98 LibGetHostIP1(TaskInstance, host, outcome);
99 Result := StrPas(outcome);
100 StrDispose(outcome);
101 StrDispose(host);
102 end
103 else
104 Result := ServerName;
105 LibClose(TaskInstance);
106end;
107
108
109procedure TrpcConfig.cboServerClick(Sender: TObject);
110var
111 index: integer;
112begin
113 {Based on selction, set port and server variable}
114 index := cboServer.ItemIndex;
115 rPort := Piece(ServerPairs[index], ',', 2);
116 pnlPort.Caption := rPort;
117 rServer := Piece(ServerPairs[index], ',', 1);
118 btnOk.Enabled := True;
119 //btnDelete.Enabled := True;
120
121 {Based on Server, get IP addresss.}
122 Panel4.Caption := GetServerIP(rServer);
123end;
124
125procedure TrpcConfig.FormCreate(Sender: TObject);
126begin
127 FormStyle := fsStayOnTop;
128 OrigHelp := Application.HelpFile; // Save original helpfile.
129 Application.HelpFile := ReadRegData(HKLM, REG_BROKER, 'BrokerDr') +
130 '\clagent.hlp'; // Identify ConnectTo helpfile.
131 ServerPairs := TStringList.Create;
132end;
133
134procedure TrpcConfig.FormClose(Sender: TObject; var Action: TCloseAction);
135begin
136 cboServer.Clear;
137 pnlPort.Caption := '';
138 ServerPairs.Free;
139 Application.HelpFile := OrigHelp; // Restore helpfile.
140end;
141
142function GetServerInfo(var Server,Port: string): integer;
143var
144 index: integer;
145 //tmp,fname,: string; {P14}
146 tmpServerPairs : TStringList; //Format: SERVER,port#
147 TextStr: String;
148 TmpServerDetail: String; {ska@HealthSevak: 02 May 15: to get user specified server & port if not already specified}
149begin
150 rpcconfig := Trpcconfig.Create(Application);
151 TaskInstance := LibOpen;
152
153 with rpcConfig do
154 begin
155 tmpServerPairs := TStringList.Create;
156 ReadRegValueNames(HKLM, REG_SERVERS, tmpServerPairs);
157 ServerPairs.Assign(tmpServerPairs);
158 tmpServerPairs.Clear;
159 ReadRegValueNames(HKCU, REG_SERVERS, tmpServerPairs);
160 for index := 0 to (tmpServerPairs.Count-1) do
161 begin
162 TextStr := tmpServerPairs[index];
163 if ServerPairs.IndexOf(TextStr) < 0 then
164 ServerPairs.Add(TextStr);
165 end;
166
167 ButtonStatus := mrOk;
168
169 if ServerPairs.Count < 1 then
170 begin
171 {begin ska@HealthSevak: 02 May 15: to get user specified server & port if not already specified, used variable and user input instead of fixed value of "BROKERSERVER,9200"}
172 TmpServerDetail := 'BROKERSERVER,9200';
173 TmpServerDetail := InputBox('VistA server details', 'No Server detail found on command line or in Registry!' +#13 + ' Please provide it in the format as ServerNameOrIP,ListnerPort:', TmpServerDetail );
174 WriteRegData(HKLM, REG_SERVERS, TmpServerDetail, '');
175 ServerPairs.Add(TmpServerDetail);
176 {end ska@HealthSevak: 02 May 15: to get user specified server & port if not already specified, used variable and user input instead of fixed value of "BROKERSERVER,9200"}
177 end;
178
179
180 if ServerPairs.Count > 1 then // P31 //need to show form
181 begin
182 //Initialize form.
183 for index := 0 to (ServerPairs.Count -1) do //Load combobox
184 cboServer.Items.Add(ServerPairs[index]);
185// cboServer.Items.Add(Piece(ServerPairs[index], ',', 1));
186 cboServer.ItemIndex := 0;
187 rServer := Piece(ServerPairs[0], ',', 1);
188 pnlPort.Caption := Piece(ServerPairs[0], ',', 2);
189 rPort := Piece(ServerPairs[0], ',', 2);
190
191 //Get and display IP address.
192 panel4.Caption := GetServerIP(rServer);
193 ShowModal; //Display form
194 end
195 else //One choice: form not shown, value returned.
196 begin
197 rServer := Piece(ServerPairs[0], ',', 1);
198 rPort := Piece(ServerPairs[0], ',', 2);
199 end;
200
201 if ButtonStatus = mrOk then
202 begin
203 Server := rServer;
204 Port := rPort;
205 end;
206 Result := ButtonStatus;
207
208 tmpServerPairs.Free;
209 libClose(TaskInstance);
210 Release;
211 end;
212end;
213
214procedure TrpcConfig.btnOkClick(Sender: TObject);
215begin
216 ButtonStatus := mrOk;
217 rServer := Piece(cboServer.Text,',',1);
218 rPort := pnlPort.Caption;
219 rpcConfig.close;
220end;
221
222procedure TrpcConfig.butCancelClick(Sender: TObject);
223begin
224 ButtonStatus := mrCancel;
225 rServer := cboServer.Text;
226 rPort := pnlPort.Caption;
227 rpcConfig.close;
228end;
229
230procedure TrpcConfig.FormDestroy(Sender: TObject);
231begin
232 ServerPairs := TStringList.Create; // {p13 - REM}
233 ServerPairs.Free; // Release Help File.
234 Application.HelpFile := OrigHelp; //
235end;
236
237procedure TrpcConfig.cboServerExit(Sender: TObject);
238begin
239 //
240end;
241
242procedure TrpcConfig.btnNewClick(Sender: TObject);
243var
244 I: Integer;
245 ServerForm: TfrmAddServer;
246 strServer, strName, strPort: String;
247begin
248 ServerForm := TfrmAddServer.Create(Self);
249 if ServerForm.ShowModal <> mrCancel then
250 begin
251 strServer := ServerForm.edtAddress.Text;
252 strPort := ServerForm.edtPortNumber.Text;
253 ServerForm.edtPortNumber.Text := strPort;
254 strName := strServer + ',' + strPort;
255 WriteRegData(HKCU, REG_SERVERS, strName, '');
256 ServerPairs.Add(strName);
257 strName := ServerPairs[ServerPairs.Count-1];
258 cboServer.Items.Add(strName);
259 for I := 0 to cboServer.Items.Count-1 do // Iterate
260 begin
261 if cboServer.Items[I] = strName then
262 cboServer.ItemIndex := I;
263 end; // for
264// cboServer.Text := strServer;
265// pnlPort.Caption := strPort;
266 cboServerClick(Self);
267 end;
268 ServerForm.Free;
269end;
270{******************************
271btnDeleteClick
272 - remove selected server,port combination from registry
273 - added 10/17/2006
274*******************************}
275procedure TrpcConfig.btnDeleteClick(Sender: TObject);
276var
277 index: integer;
278 Text: String;
279begin
280 {Based on selction, get Text value}
281 index := cboServer.ItemIndex;
282 Text := cboServer.Items[index];
283 // now delete from both locations it could be stored
284 DeleteRegData(HKLM, REG_SERVERS, Text);
285 DeleteRegData(HKCU, REG_SERVERS, Text);
286 // and update both cboServer and ServerPairs entries
287 cboServer.Items.Delete(index);
288 ServerPairs.Delete(index);
289 // and set buttons dependent on selection back to disabled
290 btnOK.Enabled := False;
291 //btnDelete.Enabled := False;
292end;
293
294end.
295
Note: See TracBrowser for help on using the repository browser.