source: trunk/Forms/UFormConnect.pas

Last change on this file was 28, checked in by chronos, 20 months ago
  • Modified: Do not create all application forms at initialization phase but dynamically.
File size: 3.5 KB
Line 
1unit UFormConnect;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 ComCtrls, Spin, UDatabase;
8
9type
10
11 { TFormConnect }
12
13 TFormConnect = class(TForm)
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 procedure FormCreate(Sender: TObject);
36 public
37 procedure Load(ConnectProfile: TDbConnectProfile);
38 procedure Save(ConnectProfile: TDbConnectProfile);
39 procedure ReloadDbEngines;
40 procedure UpdateInterface;
41 end;
42
43
44implementation
45
46{$R *.lfm}
47
48uses
49 UCore, UEngineXML, UEngineMySQL;
50
51resourcestring
52 SAnyFile = 'Any file';
53 SXmlFiles = 'XML files';
54
55{ TFormConnect }
56
57procedure TFormConnect.ButtonXmlBrowseClick(Sender: TObject);
58begin
59 OpenDialog1.Filter := SXmlFiles + ' (.xml)|*.xml|' + SAnyFile + '|*.*';
60 OpenDialog1.InitialDir := ExtractFileDir(EditXml.Text);
61 OpenDialog1.FileName := ExtractFileName(EditXml.Text);
62 if OpenDialog1.Execute then
63 EditXml.Text := OpenDialog1.FileName;
64end;
65
66procedure TFormConnect.ComboBoxDbEnginesChange(Sender: TObject);
67begin
68 UpdateInterface;
69end;
70
71procedure TFormConnect.FormCreate(Sender: TObject);
72begin
73 ReloadDbEngines;
74end;
75
76procedure TFormConnect.Load(ConnectProfile: TDbConnectProfile);
77begin
78 EditName.Text := ConnectProfile.Name;
79 //EditConnectionString.Text := Database.ConnectionString;
80 ComboBoxDbEngines.ItemIndex := ComboBoxDbEngines.Items.IndexOfObject(ConnectProfile.ClientType);
81 if (ComboBoxDbEngines.ItemIndex = -1) and (ComboBoxDbEngines.Items.Count > 0) then
82 ComboBoxDbEngines.ItemIndex := 0;
83 if ConnectProfile.Params is TDbConnectParamsXml then
84 EditXml.Text := TDbConnectParamsXml(ConnectProfile.Params).FileName;
85 if ConnectProfile.Params is TDbConnectParamsMysql then begin
86 EditHost.Text := TDbConnectParamsMysql(ConnectProfile.Params).Host;
87 SpinEditPort.Value := TDbConnectParamsMysql(ConnectProfile.Params).Port;
88 end;
89 UpdateInterface;
90end;
91
92procedure TFormConnect.Save(ConnectProfile: TDbConnectProfile);
93begin
94 ConnectProfile.Name := EditName.Text;
95 //DatabaseClient.ConnectionString := EditConnectionString.Text;
96 ConnectProfile.ClientType := TDbClientType(ComboBoxDbEngines.Items.Objects[ComboBoxDbEngines.ItemIndex]);
97 if ConnectProfile.Params is TDbConnectParamsXml then
98 TDbConnectParamsXml(ConnectProfile.Params).FileName := EditXml.Text;
99 if ConnectProfile.Params is TDbConnectParamsMysql then begin
100 TDbConnectParamsMysql(ConnectProfile.Params).Host := EditHost.Text;
101 TDbConnectParamsMysql(ConnectProfile.Params).Port := SpinEditPort.Value;
102 end;
103end;
104
105procedure TFormConnect.ReloadDbEngines;
106var
107 I: Integer;
108begin
109 ComboBoxDbEngines.Items.BeginUpdate;
110 try
111 ComboBoxDbEngines.Items.Clear;
112 for I := 0 to Core.DbManager.ClientTypes.Count - 1 do
113 ComboBoxDbEngines.Items.AddObject(Core.DbManager.ClientTypes[I].Name,
114 Core.DbManager.ClientTypes[I]);
115 finally
116 ComboBoxDbEngines.Items.Endupdate;
117 end;
118end;
119
120procedure TFormConnect.UpdateInterface;
121begin
122 PageControl1.TabIndex := ComboBoxDbEngines.ItemIndex;
123end;
124
125end.
126
Note: See TracBrowser for help on using the repository browser.