-
Notifications
You must be signed in to change notification settings - Fork 2
/
uDmConn.pas
61 lines (51 loc) · 1.3 KB
/
uDmConn.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
unit uDmConn;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.FB,
FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, Data.DB, FireDAC.Comp.Client;
type
TdmConn = class(TDataModule)
fcConn: TFDConnection;
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
function Conecta: boolean;
{ Public declarations }
end;
var
dmConn: TdmConn;
implementation
uses
IniFiles, Vcl.Forms;
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
function TdmConn.Conecta: boolean;
var
PathIni: string;
IniConf: TIniFile;
begin
PathIni := ExtractFilePath(Application.ExeName) + 'tapconf.ini';
IniConf := TIniFile.Create(PathIni);
try
try
fcConn.Params.Database := IniConf.ReadString('DB', 'PATH', '');
fcConn.Params.UserName := IniConf.ReadString('DB', 'USUARIO', '');
fcConn.Params.Password := IniConf.ReadString('DB', 'SENHA', '');
fcConn.Open;
Result := true;
except
on E: Exception do
Result := false;
end;
finally
IniConf.Free;
end;
end;
procedure TdmConn.DataModuleDestroy(Sender: TObject);
begin
fcConn.Close;
end;
end.