-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit1.pas
127 lines (98 loc) · 2.39 KB
/
unit1.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
121
122
123
124
125
126
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, mysql57conn, Forms, Controls, Graphics, Dialogs, Buttons,
StdCtrls,INIFiles,FileUtil;
type
{ Tsettings }
Tsettings = class(TForm)
host: TEdit;
database: TEdit;
login: TEdit;
password: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
okbtn: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
connection: TMySQL57Connection;
procedure BitBtn3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure okbtnClick(Sender: TObject);
private
public
end;
var
settings: Tsettings;
implementation
{$R *.lfm}
{ Tsettings }
procedure Tsettings.BitBtn3Click(Sender: TObject);
begin
connection.Connected:=False;
connection.HostName:=host.Text;
connection.DatabaseName:=database.Text;
connection.UserName:=login.text;
connection.Password:=password.text;
try
connection.Connected:=True;
except
connection.Connected:=False;
end;
if connection.Connected then okbtn.enabled := True else okbtn.enabled := False;
// okbtn.Enabled:= not(okbtn.Enabled);
end;
procedure Tsettings.FormShow(Sender: TObject);
var
inifile: string;
IniF: TINIFile;
begin
okbtn.Enabled:=False;
inifile:=ExtractFileDir(paramstr(0));
inifile:=inifile+'/settings.ini';
if FileExists(inifile) then
begin
Inif := TINIFile.Create(inifile);
host.Text := Inif.ReadString('Main','Host','');
database.Text := Inif.ReadString('Main','DataBase','');
login.Text := Inif.ReadString('Main','UserName','');
password.Text := Inif.ReadString('Main','Password','');
Inif.Destroy;
end
else
begin
host.Text:='';
database.Text:='';
login.Text:='';
password.Text:='';
end;
end;
procedure Tsettings.okbtnClick(Sender: TObject);
var
inifile: string;
IniF: TINIFile;
fp: textfile;
begin
inifile:=ExtractFileDir(paramstr(0));
inifile:=inifile+'/settings.ini';
if FileExists(inifile) then
begin
Inif := TINIFile.Create(inifile);
end
else
begin
AssignFile(fp, inifile);
rewrite(fp);
closefile(fp);
Inif := TINIFile.Create(inifile);
end;
Inif.WriteString('Main','Host',host.Text);
Inif.WriteString('Main','DataBase',database.Text);
Inif.WriteString('Main','UserName',login.Text);
Inif.WriteString('Main','Password',password.Text);
Inif.Destroy;
end;
end.