ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/IBDSDialogs.pas
Revision: 39
Committed: Tue May 17 08:14:52 2016 UTC (7 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 6588 byte(s)
Log Message:
Committing updates for Release R1-4-1

File Contents

# User Rev Content
1 tony 39 {************************************************************************}
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,
42     Forms, StdCtrls, ExtCtrls, IB, IBDialogs;
43    
44     type
45    
46     { TIBDSLCLInterface }
47    
48     TIBDSLCLInterface = class(TIBLCLInterface)
49     private
50     FSetCursorDepth: integer;
51     function GetProjectName: string;
52     procedure GetDatabaseName(DefaultDBName, DefaultUserName: string; var DBName: string;
53     var UserName: string);
54     procedure GetServerName(DefaultServerName, DefaultUserName: string;
55     var ServerName, UserName: string);
56     procedure SaveDatabaseParams(DatabaseName, UserName: string);
57     procedure SaveServerParams(ServerName, UserName: string);
58     public
59     function ServerLoginDialog(var AServerName: string;
60     var AUserName, APassword: string): Boolean; override;
61     function LoginDialogEx(var ADatabaseName: string;
62     var AUserName, APassword: string;
63     NameReadOnly: Boolean): Boolean; override;
64     end;
65    
66     implementation
67    
68     {$R *.lfm}
69    
70     uses BaseIDEIntf, LazIDEIntf;
71    
72     const
73     ConfigFile = 'ibx.xml';
74    
75     type
76     { TIBXDSLoginDlg }
77    
78     TIBXDSLoginDlg = class(TForm)
79     Bevel1: TBevel;
80     Button1: TButton;
81     Button2: TButton;
82     ProjectName: TLabel;
83     TargetCaption: TLabel;
84     Label2: TLabel;
85     Label3: TLabel;
86     Password: TEdit;
87     UserName: TEdit;
88     DatabaseName: TEdit;
89     private
90     { private declarations }
91     public
92     { public declarations }
93     end;
94    
95    
96     function TIBDSLCLInterface.GetProjectName: string;
97     begin
98     Result := ChangeFileExt(ExtractFileName(LazarusIDE.ActiveProject.MainFile.FileName),'');
99     end;
100    
101     procedure TIBDSLCLInterface.GetDatabaseName(DefaultDBName,
102     DefaultUserName: string; var DBName: string; var UserName: string);
103     begin
104     With GetIDEConfigStorage(ConfigFile,True) do
105     try
106     DBName := GetValue(GetProjectName + '/Database',DefaultDBName);
107     UserName := GetValue(GetProjectName + '/UserName',DefaultUserName);
108     finally
109     Free
110     end;
111     end;
112    
113     procedure TIBDSLCLInterface.GetServerName(DefaultServerName,
114     DefaultUserName: string; var ServerName, UserName: string);
115     begin
116     With GetIDEConfigStorage(ConfigFile,True) do
117     try
118     ServerName := GetValue(GetProjectName + '/Server',DefaultServerName);
119     UserName := GetValue(GetProjectName + '/UserName',DefaultUserName);
120     finally
121     Free
122     end;
123     end;
124    
125     procedure TIBDSLCLInterface.SaveDatabaseParams(DatabaseName, UserName: string);
126     begin
127     With GetIDEConfigStorage(ConfigFile,True) do
128     try
129     SetValue(GetProjectName + '/Database',DatabaseName);
130     SetValue(GetProjectName + '/UserName',UserName);
131     WriteToDisk;
132     finally
133     Free
134     end;
135     end;
136    
137     procedure TIBDSLCLInterface.SaveServerParams(ServerName, UserName: string);
138     begin
139     With GetIDEConfigStorage(ConfigFile,True) do
140     try
141     SetValue(GetProjectName + '/Server',ServerName);
142     SetValue(GetProjectName + '/UserName',UserName);
143     WriteToDisk;
144     finally
145     Free
146     end;
147     end;
148    
149     function TIBDSLCLInterface.ServerLoginDialog(var AServerName: string;
150     var AUserName, APassword: string): Boolean;
151     begin
152     with TIBXDSLoginDlg.Create(nil) do
153     try
154     Caption := 'Firebird Server Login';
155     TargetCaption.Caption := 'Server Name: ';
156     GetServerName(AServerName,AUserName,AServerName,AUserName);
157     ProjectName.Caption := GetProjectName;
158     DatabaseName.Text := AServerName;
159     UserName.Text := AUserName;
160     Result := False;
161     if AUserName = '' then ActiveControl := UserName;
162     if ShowModal = mrOk then
163     begin
164     AServerName := DatabaseName.Text;
165     AUserName := UserName.Text;
166     APassword := Password.Text;
167     SaveServerParams(DatabaseName.Text,UserName.Text);
168     Result := True;
169     end;
170     finally
171     Free;
172     end;
173     end;
174    
175     function TIBDSLCLInterface.LoginDialogEx(var ADatabaseName: string;
176     var AUserName, APassword: string; NameReadOnly: Boolean): Boolean;
177     begin
178     with TIBXDSLoginDlg.Create(Application) do
179     try
180     ProjectName.Caption := GetProjectName;
181     GetDatabaseName(ADatabaseName, AUserName, ADatabaseName,AUserName);
182     DatabaseName.Text := ADatabaseName;
183     UserName.Text := AUserName;
184     Result := False;
185     if NameReadOnly then
186     UserName.Enabled := False
187     else
188     if AUserName = '' then ActiveControl := UserName;
189     if ShowModal = mrOk then
190     begin
191     ADatabaseName := DatabaseName.Text;
192     AUserName := UserName.Text;
193     APassword := Password.Text;
194     SaveDatabaseParams(DatabaseName.Text,UserName.Text);
195     Result := True;
196     end
197     finally
198     Free;
199     end;
200     end;
201    
202     end.