1 |
(*
|
2 |
* IBX For Lazarus (Firebird Express)
|
3 |
*
|
4 |
* The contents of this file are subject to the Initial Developer's
|
5 |
* Public License Version 1.0 (the "License"); you may not use this
|
6 |
* file except in compliance with the License. You may obtain a copy
|
7 |
* of the License here:
|
8 |
*
|
9 |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl
|
10 |
*
|
11 |
* Software distributed under the License is distributed on an "AS
|
12 |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
13 |
* implied. See the License for the specific language governing rights
|
14 |
* and limitations under the License.
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is Tony Whyman.
|
17 |
*
|
18 |
* The Original Code is (C) 2011 Tony Whyman, MWA Software
|
19 |
* (http://www.mwasoftware.co.uk).
|
20 |
*
|
21 |
* All Rights Reserved.
|
22 |
*
|
23 |
* Contributor(s): ______________________________________.
|
24 |
*
|
25 |
*)
|
26 |
|
27 |
unit IBXServiceEditor;
|
28 |
|
29 |
{$mode objfpc}
|
30 |
|
31 |
interface
|
32 |
|
33 |
uses
|
34 |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
35 |
ExtCtrls, StdCtrls, IBXServices, IB;
|
36 |
|
37 |
type
|
38 |
|
39 |
{ TIBXServiceEditorForm }
|
40 |
|
41 |
TIBXServiceEditorForm = class(TForm)
|
42 |
Bevel1: TBevel;
|
43 |
CancelBtn: TButton;
|
44 |
ConnectionTypeBtn: TRadioGroup;
|
45 |
PortNo: TEdit;
|
46 |
Label1: TLabel;
|
47 |
ServiceParams: TMemo;
|
48 |
Label2: TLabel;
|
49 |
Label3: TLabel;
|
50 |
Label5: TLabel;
|
51 |
Label7: TLabel;
|
52 |
Label8: TLabel;
|
53 |
LoginPrompt: TCheckBox;
|
54 |
OKBtn: TButton;
|
55 |
Password: TEdit;
|
56 |
Protocol: TComboBox;
|
57 |
ServerName: TEdit;
|
58 |
Test: TButton;
|
59 |
UserName: TEdit;
|
60 |
procedure ConnectionTypeBtnSelectionChanged(Sender: TObject);
|
61 |
procedure PasswordEditingDone(Sender: TObject);
|
62 |
procedure ProtocolCloseUp(Sender: TObject);
|
63 |
procedure ServiceParamsEditingDone(Sender: TObject);
|
64 |
procedure TestClick(Sender: TObject);
|
65 |
procedure UserNameEditingDone(Sender: TObject);
|
66 |
private
|
67 |
{ private declarations }
|
68 |
function Edit: Boolean;
|
69 |
procedure AddParam(aName, Value: string);
|
70 |
procedure DeleteParam(aName: string);
|
71 |
procedure UpdateParamEditBoxes;
|
72 |
public
|
73 |
{ public declarations }
|
74 |
Service: TIBXServicesConnection;
|
75 |
end;
|
76 |
|
77 |
function EditIBXService(aService: TIBXServicesConnection): boolean;
|
78 |
|
79 |
var
|
80 |
IBXServiceEditorForm: TIBXServiceEditorForm;
|
81 |
|
82 |
implementation
|
83 |
|
84 |
{$R *.lfm}
|
85 |
|
86 |
function EditIBXService(aService: TIBXServicesConnection): boolean;
|
87 |
begin
|
88 |
with TIBXServiceEditorForm.Create(Application) do
|
89 |
try
|
90 |
Service := aService;
|
91 |
Result := Edit
|
92 |
finally
|
93 |
Free
|
94 |
end
|
95 |
end;
|
96 |
|
97 |
{ TIBXServiceEditorForm }
|
98 |
|
99 |
procedure TIBXServiceEditorForm.ConnectionTypeBtnSelectionChanged(
|
100 |
Sender: TObject);
|
101 |
begin
|
102 |
if ConnectionTypeBtn.ItemIndex = 0 then
|
103 |
begin
|
104 |
Label7.Enabled := False;
|
105 |
ServerName.Text := '';
|
106 |
ServerName.Enabled := False;
|
107 |
Protocol.ItemIndex := 3;
|
108 |
end
|
109 |
else
|
110 |
begin
|
111 |
Label7.Enabled := True;
|
112 |
ServerName.Enabled := True;
|
113 |
if Protocol.ItemIndex = 3 then
|
114 |
Protocol.ItemIndex := 4;
|
115 |
end;
|
116 |
end;
|
117 |
|
118 |
procedure TIBXServiceEditorForm.PasswordEditingDone(Sender: TObject);
|
119 |
begin
|
120 |
AddParam('password', Password.Text);
|
121 |
end;
|
122 |
|
123 |
procedure TIBXServiceEditorForm.ProtocolCloseUp(Sender: TObject);
|
124 |
begin
|
125 |
if Protocol.ItemIndex = 3 then
|
126 |
ConnectionTypeBtn.ItemIndex := 0
|
127 |
else
|
128 |
ConnectionTypeBtn.ItemIndex := 1;
|
129 |
end;
|
130 |
|
131 |
procedure TIBXServiceEditorForm.ServiceParamsEditingDone(Sender: TObject);
|
132 |
begin
|
133 |
UpdateParamEditBoxes;
|
134 |
end;
|
135 |
|
136 |
procedure TIBXServiceEditorForm.TestClick(Sender: TObject);
|
137 |
var tempService: TIBXServicesConnection; {Use as example for test}
|
138 |
begin
|
139 |
Test.Enabled := false;
|
140 |
tempService := TIBXServicesConnection.Create(nil);
|
141 |
try
|
142 |
tempService.Protocol := TProtocol(Protocol.ItemIndex);
|
143 |
tempService.ServerName := ServerName.Text;
|
144 |
tempService.PortNo := PortNo.Text;
|
145 |
tempService.Params.Assign(ServiceParams.Lines);
|
146 |
tempService.LoginPrompt := true;
|
147 |
try
|
148 |
tempService.Connected := true;
|
149 |
ShowMessage('Successful Connection');
|
150 |
tempService.Connected := false;
|
151 |
except on E: Exception do
|
152 |
ShowMessage(E.Message)
|
153 |
end;
|
154 |
finally
|
155 |
tempService.Free;
|
156 |
Test.Enabled := true;
|
157 |
end;
|
158 |
end;
|
159 |
|
160 |
procedure TIBXServiceEditorForm.UserNameEditingDone(Sender: TObject);
|
161 |
begin
|
162 |
AddParam('user_name', UserName.Text);
|
163 |
end;
|
164 |
|
165 |
function TIBXServiceEditorForm.Edit: Boolean;
|
166 |
begin
|
167 |
if Trim(Service.Params.Text) = '' then
|
168 |
ServiceParams.Clear
|
169 |
else
|
170 |
ServiceParams.Lines.Assign(Service.Params);
|
171 |
|
172 |
ServerName.Text := Service.ServerName;
|
173 |
Protocol.ItemIndex := ord(Service.Protocol);
|
174 |
LoginPrompt.Checked := Service.LoginPrompt;
|
175 |
PortNo.Text := Service.PortNo;
|
176 |
ProtocolCloseUp(nil);
|
177 |
ConnectionTypeBtnSelectionChanged(nil);
|
178 |
UpdateParamEditBoxes;
|
179 |
Result := False;
|
180 |
if ShowModal = mrOk then
|
181 |
begin
|
182 |
Service.Protocol := TProtocol(Protocol.ItemIndex);
|
183 |
Service.ServerName := ServerName.Text;
|
184 |
Service.PortNo := PortNo.Text;
|
185 |
Service.Params.Assign(ServiceParams.Lines);
|
186 |
Service.LoginPrompt := LoginPrompt.Checked;
|
187 |
Result := True;
|
188 |
end;
|
189 |
end;
|
190 |
|
191 |
procedure TIBXServiceEditorForm.AddParam(aName, Value: string);
|
192 |
begin
|
193 |
if Trim(Value) = '' then
|
194 |
DeleteParam(aName)
|
195 |
else
|
196 |
ServiceParams.Lines.Values[aName] := Trim(Value);
|
197 |
end;
|
198 |
|
199 |
procedure TIBXServiceEditorForm.DeleteParam(aName: string);
|
200 |
var
|
201 |
i: Integer;
|
202 |
begin
|
203 |
for i := 0 to ServiceParams.Lines.Count - 1 do
|
204 |
begin
|
205 |
if (Pos(aName, LowerCase(ServiceParams.Lines.Names[i])) = 1) then {mbcs ok}
|
206 |
begin
|
207 |
ServiceParams.Lines.Delete(i);
|
208 |
break;
|
209 |
end;
|
210 |
end;
|
211 |
end;
|
212 |
|
213 |
procedure TIBXServiceEditorForm.UpdateParamEditBoxes;
|
214 |
begin
|
215 |
UserName.Text := ServiceParams.Lines.Values['user_name'];
|
216 |
Password.Text := ServiceParams.Lines.Values['password'];
|
217 |
end;
|
218 |
|
219 |
|
220 |
end.
|