-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connect.pas
169 lines (151 loc) · 4.7 KB
/
Connect.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
unit Connect;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Prog_Unit, inifiles, Menus, html;
type
TFRM_Connect = class(TForm)
txt_adress: TEdit;
Label1: TLabel;
txt_port: TEdit;
Label2: TLabel;
ListBox1: TListBox;
Label3: TLabel;
btn_ok: TButton;
btn_cancel: TButton;
PopupMenu1: TPopupMenu;
Entf1: TMenuItem;
Verbinden1: TMenuItem;
txt_loginname: TEdit;
Label4: TLabel;
txt_pw: TEdit;
Label5: TLabel;
cb_save_pw: TCheckBox;
procedure ListBox1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn_okClick(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Entf1Click(Sender: TObject);
procedure Verbinden1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
inifile: string;
history: THTMLElement;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
implementation
uses languages;
{$R *.DFM}
procedure TFRM_Connect.FormCreate(Sender: TObject);
var ini: TIniFile;
c, i: integer;
child: THTMLElement;
begin
if SaveCaptions then SaveAllCaptions(Self,LangFile);
if LoadCaptions then LoadAllCaptions(Self,LangFile);
history := THTMLElement.Create(nil,'root');
inifile := ODataBase.PlayerInf;
ini := TIniFile.Create(inifile);
try
c := ini.ReadInteger('Connections','HostCount',0);
for i := 0 to c-1 do
begin
child := THTMLElement.Create(history,'server');
child.AttributeValue['host'] :=
ini.ReadString('Connections','Host'+inttostr(i),'0.0.0.0:0');
child.AttributeValue['login'] :=
ini.ReadString('Connections','login'+inttostr(i),'');
child.AttributeValue['pass'] :=
ini.ReadString('Connections','pass'+inttostr(i),'');
ListBox1.Items.Add(child.AttributeValue['host']);
end;
finally
ini.Free;
end;
end;
procedure TFRM_Connect.btn_okClick(Sender: TObject);
var ini: TIniFile;
i: integer;
child: THTMLElement;
begin
if txt_port.Text = '' then
ShowMessage(STR_MSG_kein_port_eingegeben)
else
begin
child := nil;
for i := 0 to ListBox1.Items.Count-1 do
if history.ChildElements[i].AttributeValue['host'] =
txt_adress.Text + ':' + txt_port.Text then
begin
child := history.ChildElements[i];
break;
end;
if child = nil then
begin
child := THTMLElement.Create(history, 'server');
child.AttributeValue['host'] := txt_adress.Text + ':' + txt_port.Text;
end;
child.AttributeValue['login'] := txt_loginname.Text;
if cb_save_pw.Checked then
child.AttributeValue['pass'] := txt_pw.Text
else
child.AttributeValue['pass'] := '';
inifile := ODataBase.PlayerInf;
ini := TIniFile.Create(inifile);
ini.EraseSection('Connections');
ini.WriteInteger('Connections','HostCount', history.ChildCount);
for i := 0 to history.ChildCount-1 do
begin
ini.WriteString('Connections','Host'+inttostr(i),
history.ChildElements[i].AttributeValue['host']);
ini.WriteString('Connections','login'+inttostr(i),
history.ChildElements[i].AttributeValue['login']);
ini.WriteString('Connections','pass'+inttostr(i),
history.ChildElements[i].AttributeValue['pass']);
end;
ModalResult := mrOK;
end;
end;
procedure TFRM_Connect.ListBox1Click(Sender: TObject);
var s: string;
p: integer;
begin
if ListBox1.ItemIndex <> -1 then
begin
s := history.ChildElements[ListBox1.itemindex].AttributeValue['host'];
p := pos(':',S);
txt_adress.Text := copy(s,1,p-1);
txt_port.Text := copy(s,p+1,999);
txt_loginname.Text :=
history.ChildElements[ListBox1.itemindex].AttributeValue['login'];
txt_pw.Text :=
history.ChildElements[ListBox1.itemindex].AttributeValue['pass'];
cb_save_pw.Checked := txt_pw.Text <> '';
end;
end;
procedure TFRM_Connect.ListBox1DblClick(Sender: TObject);
begin
if ListBox1.ItemIndex >= 0 then
begin
Verbinden1Click(Sender);
end;
end;
procedure TFRM_Connect.Entf1Click(Sender: TObject);
begin
if ListBox1.ItemIndex <> -1 then
begin
history.DeleteChildElement(ListBox1.itemindex);
ListBox1.Items.Delete(ListBox1.itemindex);
end;
end;
procedure TFRM_Connect.Verbinden1Click(Sender: TObject);
begin
ModalResult := mrOk;
end;
procedure TFRM_Connect.FormDestroy(Sender: TObject);
begin
history.Free;
end;
end.