ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibserviceeditor.pas
Revision: 209
Committed: Wed Mar 14 12:48:51 2018 UTC (6 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 6274 byte(s)
Log Message:
Fixes Merged

File Contents

# User Rev Content
1 tony 33 (*
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 ibserviceeditor;
28    
29     {$mode objfpc}
30    
31     interface
32    
33     uses
34     Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
35 tony 45 ExtCtrls, StdCtrls, IBServices, IB;
36 tony 33
37     type
38    
39     { TIBServiceEditorForm }
40    
41     TIBServiceEditorForm = class(TForm)
42     Bevel1: TBevel;
43     CancelBtn: TButton;
44 tony 209 PortNo: TEdit;
45     Label1: TLabel;
46 tony 33 ServiceParams: TMemo;
47     Label2: TLabel;
48     Label3: TLabel;
49     Label5: TLabel;
50     Label7: TLabel;
51     Label8: TLabel;
52     LocalRbtn: TRadioButton;
53     LoginPrompt: TCheckBox;
54     OKBtn: TButton;
55     Password: TEdit;
56     Protocol: TComboBox;
57     RemoteRbtn: TRadioButton;
58     ServerName: TEdit;
59     Test: TButton;
60     UserName: TEdit;
61     procedure LocalRbtnClick(Sender: TObject);
62     procedure PasswordChange(Sender: TObject);
63     procedure RemoteRbtnClick(Sender: TObject);
64     procedure TestClick(Sender: TObject);
65     procedure UserNameChange(Sender: TObject);
66     private
67     { private declarations }
68     function Edit: Boolean;
69     function GetParam(aName: string): string;
70     procedure AddParam(aName, Value: string);
71     procedure DeleteParam(aName: string);
72     public
73     { public declarations }
74     Service: TIBCustomService;
75     end;
76    
77     function EditIBService(aService: TIBCustomService): boolean;
78    
79     var
80     IBServiceEditorForm: TIBServiceEditorForm;
81    
82     implementation
83    
84     {$R *.lfm}
85    
86     function EditIBService(aService: TIBCustomService): boolean;
87     begin
88     with TIBServiceEditorForm.Create(Application) do
89     try
90     Service := aService;
91     Result := Edit
92     finally
93     Free
94     end
95     end;
96    
97     { TIBServiceEditorForm }
98    
99     procedure TIBServiceEditorForm.LocalRbtnClick(Sender: TObject);
100     begin
101     Label7.Enabled := False;
102     Label8.Enabled := False;
103     ServerName.Enabled := False;
104     Protocol.Enabled := False;
105     end;
106    
107     procedure TIBServiceEditorForm.PasswordChange(Sender: TObject);
108     begin
109     AddParam('password', Password.Text);
110     end;
111    
112     procedure TIBServiceEditorForm.RemoteRbtnClick(Sender: TObject);
113     begin
114     Label7.Enabled := True;
115     Label8.Enabled := True;
116     Protocol.Enabled := True;
117     ServerName.Enabled := True;
118     if Protocol.Text = '' then
119     Protocol.Text := 'TCP';
120     end;
121    
122     procedure TIBServiceEditorForm.TestClick(Sender: TObject);
123     var tempService: TIBControlService; {Use as example for test}
124     begin
125     Test.Enabled := false;
126     tempService := TIBControlService.Create(nil);
127     try
128     if LocalRbtn.Checked then
129     begin
130     tempService.ServerName := '';
131     tempService.Protocol := Local;
132     end
133     else
134     begin
135     case Protocol.ItemIndex of
136     0: tempService.Protocol := TCP;
137     1: tempService.Protocol := NamedPipe;
138     2: tempService.Protocol := SPX;
139     end;
140     tempService.ServerName := ServerName.Text
141     end;
142 tony 209 tempService.PortNo := PortNo.Text;
143 tony 33 tempService.Params.Assign(ServiceParams.Lines);
144     tempService.LoginPrompt := true;
145     try
146     tempService.Active := true;
147     ShowMessage('Successful Connection');
148     tempService.Active := false;
149     except on E: Exception do
150     ShowMessage(E.Message)
151     end;
152     finally
153     tempService.Free;
154     Test.Enabled := true;
155     end;
156     end;
157    
158     procedure TIBServiceEditorForm.UserNameChange(Sender: TObject);
159     begin
160     AddParam('user_name', UserName.Text);
161     end;
162    
163     function TIBServiceEditorForm.Edit: Boolean;
164     begin
165     if Trim(Service.Params.Text) = '' then
166     ServiceParams.Clear
167     else
168     ServiceParams.Lines.Assign(Service.Params);
169    
170     ServerName.Text := Service.ServerName;
171     LoginPrompt.Checked := Service.LoginPrompt;
172 tony 209 PortNo.Text := Service.PortNo;
173 tony 33 UserName.Text := GetParam('user_name');
174     Password.Text := GetParam('password');
175     RemoteRbtn.Checked := (Service.Protocol <> Local);
176     Result := False;
177     if ShowModal = mrOk then
178     begin
179     if LocalRbtn.Checked then
180     begin
181     Service.Protocol := Local;
182     Service.ServerName := ''
183     end
184     else
185     begin
186     case Protocol.ItemIndex of
187     0: Service.Protocol := TCP;
188     1: Service.Protocol := NamedPipe;
189     2: Service.Protocol := SPX;
190     end;
191     Service.ServerName := ServerName.Text
192     end;
193     Service.Params := ServiceParams.Lines;
194     Service.LoginPrompt := LoginPrompt.Checked;
195 tony 209 Service.PortNo := PortNo.Text;
196 tony 33 Result := True;
197     end;
198     end;
199    
200     function TIBServiceEditorForm.GetParam(aName: string): string;
201     var
202     i: Integer;
203     begin
204     Result := '';
205     for i := 0 to ServiceParams.Lines.Count - 1 do
206     begin
207     if (Pos(aName, LowerCase(ServiceParams.Lines.Names[i])) = 1) then
208     begin
209     Result := ServiceParams.Lines.Values[ServiceParams.Lines.Names[i]];
210     break;
211     end;
212     end;
213     end;
214    
215     procedure TIBServiceEditorForm.AddParam(aName, Value: string);
216     var
217     i: Integer;
218     found: boolean;
219     begin
220     found := False;
221     if Trim(Value) <> '' then
222     begin
223     ServiceParams.Lines.NameValueSeparator := '=';
224     for i := 0 to ServiceParams.Lines.Count - 1 do
225     begin
226     if (Pos(aName, LowerCase(ServiceParams.Lines.Names[i])) = 1) then {mbcs ok}
227     begin
228     ServiceParams.Lines.Values[ServiceParams.Lines.Names[i]] := Value;
229     found := True;
230     break;
231     end;
232     end;
233     if not found then
234     ServiceParams.Lines.Add(aName + '=' + Value);
235     end
236     else
237     DeleteParam(Name);
238     end;
239    
240     procedure TIBServiceEditorForm.DeleteParam(aName: string);
241     var
242     i: Integer;
243     begin
244     for i := 0 to ServiceParams.Lines.Count - 1 do
245     begin
246     if (Pos(aName, LowerCase(ServiceParams.Lines.Names[i])) = 1) then {mbcs ok}
247     begin
248     ServiceParams.Lines.Delete(i);
249     break;
250     end;
251     end;
252     end;
253    
254    
255     end.