ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/IBXServiceEditor.pas
Revision: 267
Committed: Fri Dec 28 10:44:23 2018 UTC (5 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 6584 byte(s)
Log Message:
Fixes Merged

File Contents

# Content
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 ConfigOverrides: TMemo;
45 ConnectionTypeBtn: TRadioGroup;
46 Label10: TLabel;
47 PortNo: TEdit;
48 Label1: TLabel;
49 ServiceParams: TMemo;
50 Label2: TLabel;
51 Label3: TLabel;
52 Label5: TLabel;
53 Label7: TLabel;
54 Label8: TLabel;
55 LoginPrompt: TCheckBox;
56 OKBtn: TButton;
57 Password: TEdit;
58 Protocol: TComboBox;
59 ServerName: TEdit;
60 Test: TButton;
61 UserName: TEdit;
62 UseWireCompression: TCheckBox;
63 procedure ConfigOverridesEditingDone(Sender: TObject);
64 procedure ConnectionTypeBtnSelectionChanged(Sender: TObject);
65 procedure PasswordEditingDone(Sender: TObject);
66 procedure ProtocolCloseUp(Sender: TObject);
67 procedure ServiceParamsEditingDone(Sender: TObject);
68 procedure TestClick(Sender: TObject);
69 procedure UserNameEditingDone(Sender: TObject);
70 procedure UseWireCompressionEditingDone(Sender: TObject);
71 private
72 { private declarations }
73 FChanging: boolean;
74 function Edit: Boolean;
75 procedure AddParam(aName, Value: string);
76 procedure DeleteParam(aName: string);
77 procedure UpdateParamEditBoxes;
78 public
79 { public declarations }
80 Service: TIBXServicesConnection;
81 end;
82
83 function EditIBXService(aService: TIBXServicesConnection): boolean;
84
85 var
86 IBXServiceEditorForm: TIBXServiceEditorForm;
87
88 implementation
89
90 {$R *.lfm}
91
92 function EditIBXService(aService: TIBXServicesConnection): boolean;
93 begin
94 with TIBXServiceEditorForm.Create(Application) do
95 try
96 Service := aService;
97 Result := Edit
98 finally
99 Free
100 end
101 end;
102
103 { TIBXServiceEditorForm }
104
105 procedure TIBXServiceEditorForm.ConnectionTypeBtnSelectionChanged(
106 Sender: TObject);
107 begin
108 if ConnectionTypeBtn.ItemIndex = 0 then
109 begin
110 Label7.Enabled := False;
111 ServerName.Text := '';
112 ServerName.Enabled := False;
113 Protocol.ItemIndex := 3;
114 end
115 else
116 begin
117 Label7.Enabled := True;
118 ServerName.Enabled := True;
119 if Protocol.ItemIndex = 3 then
120 Protocol.ItemIndex := 4;
121 end;
122 end;
123
124 procedure TIBXServiceEditorForm.ConfigOverridesEditingDone(Sender: TObject);
125 begin
126 FChanging := true;
127 try
128 UseWireCompression.Checked := CompareText(ConfigOverrides.Lines.Values['WireCompression'],'true') = 0;
129 finally
130 FChanging := false;
131 end;
132 end;
133
134 procedure TIBXServiceEditorForm.PasswordEditingDone(Sender: TObject);
135 begin
136 AddParam('password', Password.Text);
137 end;
138
139 procedure TIBXServiceEditorForm.ProtocolCloseUp(Sender: TObject);
140 begin
141 if Protocol.ItemIndex = 3 then
142 ConnectionTypeBtn.ItemIndex := 0
143 else
144 ConnectionTypeBtn.ItemIndex := 1;
145 end;
146
147 procedure TIBXServiceEditorForm.ServiceParamsEditingDone(Sender: TObject);
148 begin
149 UpdateParamEditBoxes;
150 end;
151
152 procedure TIBXServiceEditorForm.TestClick(Sender: TObject);
153 var tempService: TIBXServicesConnection; {Use as example for test}
154 begin
155 Test.Enabled := false;
156 tempService := TIBXServicesConnection.Create(nil);
157 try
158 tempService.Protocol := TProtocol(Protocol.ItemIndex);
159 tempService.ServerName := ServerName.Text;
160 tempService.PortNo := PortNo.Text;
161 tempService.Params.Assign(ServiceParams.Lines);
162 tempService.LoginPrompt := true;
163 try
164 tempService.Connected := true;
165 ShowMessage('Successful Connection');
166 tempService.Connected := false;
167 except on E: Exception do
168 ShowMessage(E.Message)
169 end;
170 finally
171 tempService.Free;
172 Test.Enabled := true;
173 end;
174 end;
175
176 procedure TIBXServiceEditorForm.UserNameEditingDone(Sender: TObject);
177 begin
178 AddParam('user_name', UserName.Text);
179 end;
180
181 procedure TIBXServiceEditorForm.UseWireCompressionEditingDone(Sender: TObject);
182 var Index: integer;
183 begin
184 if FChanging then Exit;
185 if UseWireCompression.Checked then
186 ConfigOverrides.Lines.Values['WireCompression'] := 'true'
187 else
188 begin
189 Index := ConfigOverrides.Lines.IndexOfName('WireCompression');
190 if Index <> -1 then
191 ConfigOverrides.Lines.Delete(Index);
192 end;
193 end;
194
195 function TIBXServiceEditorForm.Edit: Boolean;
196 begin
197 ServiceParams.Lines.Assign(Service.Params);
198 ConfigOverrides.Lines.Assign(Service.ConfigOverrides);
199
200 ServerName.Text := Service.ServerName;
201 Protocol.ItemIndex := ord(Service.Protocol);
202 LoginPrompt.Checked := Service.LoginPrompt;
203 UseWireCompression.Checked := Service.WireCompression;
204 PortNo.Text := Service.PortNo;
205 ProtocolCloseUp(nil);
206 ConnectionTypeBtnSelectionChanged(nil);
207 UpdateParamEditBoxes;
208 Result := False;
209 if ShowModal = mrOk then
210 begin
211 Service.Protocol := TProtocol(Protocol.ItemIndex);
212 Service.ServerName := ServerName.Text;
213 Service.PortNo := PortNo.Text;
214 Service.Params.Assign(ServiceParams.Lines);
215 Service.ConfigOverrides.Assign(ConfigOverrides.Lines);
216 Service.LoginPrompt := LoginPrompt.Checked;
217 Result := True;
218 end;
219 end;
220
221 procedure TIBXServiceEditorForm.AddParam(aName, Value: string);
222 begin
223 if Trim(Value) = '' then
224 DeleteParam(aName)
225 else
226 ServiceParams.Lines.Values[aName] := Trim(Value);
227 end;
228
229 procedure TIBXServiceEditorForm.DeleteParam(aName: string);
230 var
231 i: Integer;
232 begin
233 for i := 0 to ServiceParams.Lines.Count - 1 do
234 begin
235 if (Pos(aName, LowerCase(ServiceParams.Lines.Names[i])) = 1) then {mbcs ok}
236 begin
237 ServiceParams.Lines.Delete(i);
238 break;
239 end;
240 end;
241 end;
242
243 procedure TIBXServiceEditorForm.UpdateParamEditBoxes;
244 begin
245 UserName.Text := ServiceParams.Lines.Values['user_name'];
246 Password.Text := ServiceParams.Lines.Values['password'];
247 end;
248
249
250 end.