-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseOption.pas
120 lines (106 loc) · 3.47 KB
/
DatabaseOption.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
unit DatabaseOption;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,IniFiles, acPNG, ExtCtrls;
type
TfrDatabaseOption = class(TForm)
tPath: TEdit;
bBrowse: TBitBtn;
bConnection: TButton;
odlg_DBOption: TOpenDialog;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure bBrowseClick(Sender: TObject);
procedure bConnectionClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SettingConnection;
end;
var
frDatabaseOption: TfrDatabaseOption;
Create_InIFile:TIniFile;
sPath:string;
implementation
uses DataModule,comObj, ADODB;
{$R *.dfm}
procedure TfrDatabaseOption.SettingConnection;
begin
Create_InIFile:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
sPath:=Create_InIFile.ReadString('database','path',sPath);
finally
Create_InIFile.Free
end;
if (not FileExists(sPath)) and (Trim(sPath)<>'') then
begin
ShowMessage('Pilih database terlebih dahulu !');
exit
end;
With dm.AdoConn do
begin
try
Connected:=False;
{ConnectionString:='Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source='
+sPath+';Persist Security Info=False;';}
ConnectionString:='Provider=Microsoft.ACE.OLEDB.12.0;User ID=admin;Data Source='+sPath+
';Mode=Share Deny None;Persist Security Info=True;Jet OLEDB:System database="";Jet '+
'OLEDB:Registry Path="";Jet OLEDB:Database Password=yanwars;'+
'Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet '+
'OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;'+
'Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;'+
'Jet OLEDB:Encrypt Database=False;Jet OLEDB:Compact Without Replica Repair=False;'+
'Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False';
Connected:=True;
Except
on EOleException do
begin
ShowMessage('Koneksi gagal !');
Connected:=False;
frDatabaseOption.ShowModal;
end;
end;
end;
end;
procedure TfrDatabaseOption.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
// Action:=caFree;
end;
procedure TfrDatabaseOption.bBrowseClick(Sender: TObject);
begin
if odlg_DBOption.Execute=True then
begin
tPath.Text:=odlg_DBOption.FileName;
Create_InIFile:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
Create_InIFile.WriteString('database','Path',odlg_DBOption.FileName);
finally
Create_InIFile.Free;
end; // try
end;
end;
procedure TfrDatabaseOption.bConnectionClick(Sender: TObject);
begin
if FileExists(odlg_DBOption.FileName) then
begin
SettingConnection;
Close;
end;
end;
procedure TfrDatabaseOption.FormCreate(Sender: TObject);
begin
Create_InIFile:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
sPath:=Create_InIFile.ReadString('database','path',sPath);
tPath.Text:=sPath;
finally
Create_InIFile.Free
end;
end;
end.