-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathu_DatabaseConnection.pas
96 lines (71 loc) · 2.6 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
unit u_DatabaseConnection;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ADODB, DB;
type
TfrmDatabaseConnection = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
conApplication: TADOConnection;
tblAccounts, tblActiveRound, tblTournaments, tblTournamentUsers,
tblTournamentUserStats: TADOTable;
dsrAccounts, dsrActiveRound, dsrTournaments, dsrTournamentUsers
: TDataSource;
qrQuery: TADOQuery;
end;
var
frmDatabaseConnection: TfrmDatabaseConnection;
implementation
{$R *.dfm}
procedure TfrmDatabaseConnection.FormCreate(Sender: TObject);
begin
// Dynamically create modules on form.
conApplication := TADOConnection.Create(frmDatabaseConnection);
tblAccounts := TADOTable.Create(frmDatabaseConnection);
tblActiveRound := TADOTable.Create(frmDatabaseConnection);
tblTournaments := TADOTable.Create(frmDatabaseConnection);
tblTournamentUsers := TADOTable.Create(frmDatabaseConnection);
tblTournamentUserStats := TADOTable.Create(frmDatabaseConnection);
dsrAccounts := TDataSource.Create(frmDatabaseConnection);
dsrActiveRound := TDataSource.Create(frmDatabaseConnection);
dsrTournamentUsers := TDataSource.Create(frmDatabaseConnection);
qrQuery := TADOQuery.Create(frmDatabaseConnection);
// Ready connection string.
conApplication.Close;
// Looks in debug folder.
conApplication.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' +
ExtractFilePath(ParamStr(0)) + 'dbmStorage.mdb' +
'; Persist Security Info=False';
// Define prop of connection.
conApplication.LoginPrompt := False;
conApplication.Open;
// Link tables.
tblAccounts.Connection := conApplication;
tblAccounts.TableName := 'tblAccounts';
tblActiveRound.Connection := conApplication;
tblActiveRound.TableName := 'tblActiveRound';
tblTournaments.Connection := conApplication;
tblTournaments.TableName := 'tblTournaments';
tblTournamentUsers.Connection := conApplication;
tblTournamentUsers.TableName := 'tblTUsers';
tblTournamentUserStats.Connection := conApplication;
tblTournamentUserStats.TableName := 'tblTUserStats';
qrQuery.Connection := conApplication;
// Set dataset.
dsrAccounts.DataSet := tblAccounts;
dsrActiveRound.DataSet := tblActiveRound;
dsrTournamentUsers.DataSet := tblTournamentUsers;
// Ready for use.
tblAccounts.Open;
tblActiveRound.Open;
tblTournaments.Open;
tblTournamentUsers.Open;
tblTournamentUserStats.Open;
end;
end.