source: trunk/Forms/FormConnect.pas

Last change on this file was 32, checked in by chronos, 6 months ago
  • Modified: Removed U prefix from units names.
  • Modified: Use TFormEx for all forms.
File size: 3.7 KB
Line 
1unit FormConnect;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 ComCtrls, Spin, DbEngine, FormEx;
8
9type
10
11 { TFormConnect }
12
13 TFormConnect = class(TFormEx)
14 ButtonXmlBrowse: TButton;
15 ButtonOk: TButton;
16 ButtonCancel: TButton;
17 ComboBoxDbEngines: TComboBox;
18 EditHost: TEdit;
19 EditXml: TEdit;
20 EditName: TEdit;
21 Label1: TLabel;
22 Label2: TLabel;
23 Label3: TLabel;
24 Label4: TLabel;
25 Label5: TLabel;
26 OpenDialog1: TOpenDialog;
27 PageControl1: TPageControl;
28 SpinEditPort: TSpinEdit;
29 TabSheetSqlite: TTabSheet;
30 TabSheetRegistry: TTabSheet;
31 TabSheetXml: TTabSheet;
32 TabSheetSql: TTabSheet;
33 procedure ButtonXmlBrowseClick(Sender: TObject);
34 procedure ComboBoxDbEnginesChange(Sender: TObject);
35 private
36 FDbManager: TDbManager;
37 procedure SetDbManager(AValue: TDbManager);
38 public
39 procedure Load(ConnectProfile: TDbConnectProfile);
40 procedure Save(ConnectProfile: TDbConnectProfile);
41 procedure ReloadDbEngines;
42 procedure UpdateInterface;
43 property DbManager: TDbManager read FDbManager write SetDbManager;
44 end;
45
46
47implementation
48
49{$R *.lfm}
50
51uses
52 EngineXML, EngineMySQL;
53
54resourcestring
55 SAnyFile = 'Any file';
56 SXmlFiles = 'XML files';
57
58{ TFormConnect }
59
60procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
61begin
62 OpenDialog1.Filter := SXmlFiles + ' (.xml)|*.xml|' + SAnyFile + '|*.*';
63 OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
64 OpenDialog1.FileName := ExtractFileName(EditXml.Text);
65 if OpenDialog1.Execute then
66 EditXml.Text := OpenDialog1.FileName;
67end;
68
69procedure TFormConnect.ComboBoxDbEnginesChange(Sender: TObject);
70begin
71 UpdateInterface;
72end;
73
74procedure TFormConnect.SetDbManager(AValue: TDbManager);
75begin
76 if FDbManager = AValue then Exit;
77 FDbManager := AValue;
78 ReloadDbEngines;
79end;
80
81procedure TFormConnect.Load(ConnectProfile: TDbConnectProfile);
82begin
83 EditName.Text := ConnectProfile.Name;
84 //EditConnectionString.Text := Database.ConnectionString;
85 ComboBoxDbEngines.ItemIndex := ComboBoxDbEngines.Items.IndexOfObject(ConnectProfile.ClientType);
86 if (ComboBoxDbEngines.ItemIndex = -1) and (ComboBoxDbEngines.Items.Count > 0) then
87 ComboBoxDbEngines.ItemIndex := 0;
88 if ConnectProfile.Params is TDbConnectParamsXml then
89 EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
90 if ConnectProfile.Params is TDbConnectParamsMysql then begin
91 EditHost.Text := TDbConnectParamsMysql(ConnectProfile.Params).Host;
92 SpinEditPort.Value := TDbConnectParamsMysql(ConnectProfile.Params).Port;
93 end;
94 UpdateInterface;
95end;
96
97procedure TFormConnect.Save(ConnectProfile: TDbConnectProfile);
98begin
99 ConnectProfile.Name := EditName.Text;
100 //DatabaseClient.ConnectionString := EditConnectionString.Text;
101 ConnectProfile.ClientType := TDbClientType(ComboBoxDbEngines.Items.Objects[ComboBoxDbEngines.ItemIndex]);
102 if ConnectProfile.Params is TDbConnectParamsXml then
103 TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
104 if ConnectProfile.Params is TDbConnectParamsMysql then begin
105 TDbConnectParamsMysql(ConnectProfile.Params).Host := EditHost.Text;
106 TDbConnectParamsMysql(ConnectProfile.Params).Port := SpinEditPort.Value;
107 end;
108end;
109
110procedure TFormConnect.ReloadDbEngines;
111var
112 I: Integer;
113begin
114 ComboBoxDbEngines.Items.BeginUpdate;
115 try
116 ComboBoxDbEngines.Items.Clear;
117 for I := 0 to DbManager.ClientTypes.Count - 1 do
118 ComboBoxDbEngines.Items.AddObject(DbManager.ClientTypes[I].Name,
119 DbManager.ClientTypes[I]);
120 finally
121 ComboBoxDbEngines.Items.Endupdate;
122 end;
123end;
124
125procedure TFormConnect.UpdateInterface;
126begin
127 PageControl1.TabIndex := ComboBoxDbEngines.ItemIndex;
128end;
129
130end.
131
Note: See TracBrowser for help on using the repository browser.