-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu_DatabaseConnection.pas
99 lines (72 loc) · 2.42 KB
/
u_DatabaseConnection.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
unit u_DatabaseConnection;
interface
uses
System.SysUtils, System.Classes, ADODB, DB;
type
TdmConnection = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
conApplication: TADOConnection;
tblUsers, tblObjectives, tblLink, tblSignatures: TADOTable;
dsrUsers, dsrObjectives, dsrLink, dsrSignatures, dsrSQL: TDataSource;
qrQuery: TADOQuery;
end;
var
dmConnection: TdmConnection;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
procedure TdmConnection.DataModuleCreate(Sender: TObject);
begin
// Dynamically create modules on form. (TADOConnection)
conApplication := TADOConnection.Create(dmConnection);
// Dynamically create modules on form. (TADOTable)
tblUsers := TADOTable.Create(dmConnection);
tblObjectives := TADOTable.Create(dmConnection);
tblLink := TADOTable.Create(dmConnection);
tblSignatures := TADOTable.Create(dmConnection);
// Dynamically create modules on form. (DataSource)
dsrUsers := TDataSource.Create(dmConnection);
dsrObjectives := TDataSource.Create(dmConnection);
dsrLink := TDataSource.Create(dmConnection);
dsrSignatures := TDataSource.Create(dmConnection);
dsrSQL := TDataSource.Create(dmConnection);
// Dynamically create modules on form. (TADOQuery)
qrQuery := TADOQuery.Create(dmConnection);
// Ready connection string.
conApplication.Close;
// Win32/Debug.
conApplication.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' +
ExtractFilePath(ParamStr(0)) + 'dbmApplication.mdb' +
'; Persist Security Info=False';
// Define prop of connection.
conApplication.LoginPrompt := False;
conApplication.Open;
// Link tables.
tblUsers.Connection := conApplication;
tblUsers.TableName := 'tblUsers';
tblObjectives.Connection := conApplication;
tblObjectives.TableName := 'tblObjectives';
tblLink.Connection := conApplication;
tblLink.TableName := 'tblLink';
tblSignatures.Connection := conApplication;
tblSignatures.TableName := 'tblSignatures';
// SQL init.
qrQuery.Connection := conApplication;
dsrSQL.DataSet := qrQuery;
// Set source of dataset.
dsrUsers.DataSet := tblUsers;
dsrObjectives.DataSet := tblObjectives;
dsrLink.DataSet := tblLink;
dsrSignatures.DataSet := tblSignatures;
// Ready for use.
tblUsers.Open;
tblObjectives.Open;
tblLink.Open;
tblSignatures.Open;
end;
end.