ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/IBDSDialogs.pas
Revision: 45
Committed: Tue Dec 6 10:33:46 2016 UTC (7 years, 4 months ago) by tony
Content type: text/x-pascal
File size: 7054 byte(s)
Log Message:
Committing updates for Release R2-0-0

File Contents

# Content
1 {************************************************************************}
2 { }
3 { Borland Delphi Visual Component Library }
4 { InterBase Express core components }
5 { }
6 { Copyright (c) 1998-2000 Inprise Corporation }
7 { }
8 { InterBase Express is based in part on the product }
9 { Free IB Components, written by Gregory H. Deatz for }
10 { Hoagland, Longo, Moran, Dunst & Doukas Company. }
11 { Free IB Components is used under license. }
12 { }
13 { The contents of this file are subject to the InterBase }
14 { Public License Version 1.0 (the "License"); you may not }
15 { use this file except in compliance with the License. You }
16 { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17 { Software distributed under the License is distributed on }
18 { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
19 { express or implied. See the License for the specific language }
20 { governing rights and limitations under the License. }
21 { The Original Code was created by InterBase Software Corporation }
22 { and its successors. }
23 { Portions created by Inprise Corporation are Copyright (C) Inprise }
24 { Corporation. All Rights Reserved. }
25 { Contributor(s): Jeff Overcash }
26 { }
27 {************************************************************************}
28
29 unit IBDSDialogs;
30
31 {$mode objfpc}{$H+}
32
33 interface
34
35 uses
36 {$IFDEF WINDOWS }
37 Windows,
38 {$ELSE}
39 unix,
40 {$ENDIF}
41 SysUtils, Classes, Graphics, Controls, Dialogs,
42 Forms, StdCtrls, ExtCtrls, Buttons, IB, IBDialogs;
43
44 type
45 { TIBDSLCLInterface }
46
47 TIBDSLCLInterface = class(TIBLCLInterface)
48 private
49 function GetProjectName: string;
50 procedure GetDatabaseName(DefaultDBName, DefaultUserName: string; var DBName: string;
51 var UserName: string);
52 procedure GetServerName(DefaultServerName, DefaultUserName: string;
53 var ServerName, UserName: string);
54 procedure SaveDatabaseParams(DatabaseName, UserName: string);
55 procedure SaveServerParams(ServerName, UserName: string);
56 public
57 function ServerLoginDialog(var AServerName: string;
58 var AUserName, APassword: string): Boolean; override;
59 function LoginDialogEx(var ADatabaseName: string;
60 var AUserName, APassword: string;
61 NameReadOnly: Boolean): Boolean; override;
62 end;
63
64 implementation
65
66 {$R *.lfm}
67
68 uses BaseIDEIntf, LazIDEIntf;
69
70 const
71 ConfigFile = 'ibx.xml';
72
73 type
74 { TIBXDSLoginDlg }
75
76 TIBXDSLoginDlg = class(TForm)
77 Bevel1: TBevel;
78 Button1: TButton;
79 Button2: TButton;
80 Label1: TLabel;
81 OpenDialog1: TOpenDialog;
82 ProjectName: TLabel;
83 SpeedButton1: TSpeedButton;
84 TargetCaption: TLabel;
85 Label2: TLabel;
86 Label3: TLabel;
87 Password: TEdit;
88 UserName: TEdit;
89 DatabaseName: TEdit;
90 procedure SpeedButton1Click(Sender: TObject);
91 private
92 { private declarations }
93 public
94 { public declarations }
95 end;
96
97
98 { TIBXDSLoginDlg }
99
100 procedure TIBXDSLoginDlg.SpeedButton1Click(Sender: TObject);
101 begin
102 OpenDialog1.InitialDir := ExtractFileDir(DatabaseName.Text);
103 if OpenDialog1.Execute then
104 DatabaseName.Text := OpenDialog1.FileName;
105 end;
106
107
108 function TIBDSLCLInterface.GetProjectName: string;
109 begin
110 Result := ChangeFileExt(ExtractFileName(LazarusIDE.ActiveProject.MainFile.FileName),'');
111 end;
112
113 procedure TIBDSLCLInterface.GetDatabaseName(DefaultDBName,
114 DefaultUserName: string; var DBName: string; var UserName: string);
115 begin
116 With GetIDEConfigStorage(ConfigFile,True) do
117 try
118 DBName := GetValue(GetProjectName + '/Database',DefaultDBName);
119 UserName := GetValue(GetProjectName + '/UserName',DefaultUserName);
120 finally
121 Free
122 end;
123 end;
124
125 procedure TIBDSLCLInterface.GetServerName(DefaultServerName,
126 DefaultUserName: string; var ServerName, UserName: string);
127 begin
128 With GetIDEConfigStorage(ConfigFile,True) do
129 try
130 ServerName := GetValue(GetProjectName + '/Server',DefaultServerName);
131 UserName := GetValue(GetProjectName + '/UserName',DefaultUserName);
132 finally
133 Free
134 end;
135 end;
136
137 procedure TIBDSLCLInterface.SaveDatabaseParams(DatabaseName, UserName: string);
138 begin
139 With GetIDEConfigStorage(ConfigFile,True) do
140 try
141 SetValue(GetProjectName + '/Database',DatabaseName);
142 SetValue(GetProjectName + '/UserName',UserName);
143 WriteToDisk;
144 finally
145 Free
146 end;
147 end;
148
149 procedure TIBDSLCLInterface.SaveServerParams(ServerName, UserName: string);
150 begin
151 With GetIDEConfigStorage(ConfigFile,True) do
152 try
153 SetValue(GetProjectName + '/Server',ServerName);
154 SetValue(GetProjectName + '/UserName',UserName);
155 WriteToDisk;
156 finally
157 Free
158 end;
159 end;
160
161 function TIBDSLCLInterface.ServerLoginDialog(var AServerName: string;
162 var AUserName, APassword: string): Boolean;
163 begin
164 with TIBXDSLoginDlg.Create(nil) do
165 try
166 Caption := 'Firebird Server Login';
167 TargetCaption.Caption := 'Server Name: ';
168 GetServerName(AServerName,AUserName,AServerName,AUserName);
169 ProjectName.Caption := GetProjectName;
170 DatabaseName.Text := AServerName;
171 UserName.Text := AUserName;
172 Result := False;
173 if AUserName = '' then ActiveControl := UserName;
174 if ShowModal = mrOk then
175 begin
176 AServerName := DatabaseName.Text;
177 AUserName := UserName.Text;
178 APassword := Password.Text;
179 SaveServerParams(DatabaseName.Text,UserName.Text);
180 Result := True;
181 end;
182 finally
183 Free;
184 end;
185 end;
186
187 function TIBDSLCLInterface.LoginDialogEx(var ADatabaseName: string;
188 var AUserName, APassword: string; NameReadOnly: Boolean): Boolean;
189 begin
190 try
191 with TIBXDSLoginDlg.Create(Application) do
192 try
193 ProjectName.Caption := GetProjectName;
194 GetDatabaseName(ADatabaseName, AUserName, ADatabaseName,AUserName);
195 DatabaseName.Text := ADatabaseName;
196 UserName.Text := AUserName;
197 Result := False;
198 if NameReadOnly then
199 UserName.Enabled := False
200 else
201 if AUserName = '' then ActiveControl := UserName;
202 if ShowModal = mrOk then
203 begin
204 ADatabaseName := DatabaseName.Text;
205 AUserName := UserName.Text;
206 APassword := Password.Text;
207 SaveDatabaseParams(DatabaseName.Text,UserName.Text);
208 Result := True;
209 end
210 finally
211 Free;
212 end;
213 except On E:Exception do
214 MessageDlg('Unable to Load Login Dialog ' + E.Message,mtError,[mbOK],0);
215 end;
216 end;
217
218 end.