TStrings读写ini文件
procedure TForm1.Button1Click(Sender: TObject);
var
ts: TStrings;
SysPath: string;
begin
ts := TstringList.Create;
SysPath := ExtractFilePath(Application.ExeName);
try
ts.Values['IP'] := Edit1.Text;
ts.Values['Port'] := Edit2.Text;
ts.Values['HYDWID'] := Edit3.Text; //SysPath 是系统的目录,这个没有问题
ts.SaveToFile(SysPath + 'config.ini');
finally
ts.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
HYDWID, Port, ip: string;
ts: TStrings;
SysPath: string;
begin
ts := TStringList.Create;
SysPath := ExtractFilePath(Application.ExeName);
try
if FileExists(SysPath + 'config.ini') then
begin
ts.LoadFromFile(SysPath + 'config.ini');
IP := ts.Values['IP'];
Port := ts.Values['Port'];
HYDWID := ts.Values['HYDWID'];
Edit1.Text := IP;
Edit2.Text := Port;
Edit3.Text := HYDWID;
end;
finally
ts.Free;
end;
end;