其实你看看帮助文件就会了,关键词是TRegistry或TIniFiles。
给一个ini文件的例子:
uses Inifiles;
procedure Tfrmmain.OpenIni;
begin
ini:=Tinifile.create(mydir+'Nbtstat.ini');
if not fileexists('Nbtstat.ini')
then
begin
ini.writeInteger('window position','top',top);
ini.writeInteger('window position','left',left);
ini.writeInteger('window position','width',width);
ini.writeInteger('window position','height',height);
ini.writeString('IP','IP1',Edit1.Text);
ini.writeString('IP','IP2',Edit2.Text);
end
else
begin
top:=ini.ReadInteger('window position','top',50);
left:=ini.ReadInteger('window position','left',50);
width:=ini.ReadInteger('window position','width',500);
height:=ini.ReadInteger('window position','height',50);
Edit1.Text:=ini.ReadString('IP','IP1',Edit1.Text);
Edit2.Text:=ini.ReadString('IP','IP2',Edit2.Text);
end;
ini.Free;
end;
procedure Tfrmmain.SaveIni;
begin
if mydir[1]='/' then exit; //open on the LAN
//showmessage(mydir);
ini:=Tinifile.create(mydir+'Nbtstat.ini');
ini.writeInteger('window position','top',top);
ini.writeInteger('window position','left',left);
ini.writeInteger('window position','width',width);
ini.writeInteger('window position','height',height);
ini.writeString('IP','IP1',Edit1.Text);
ini.writeString('IP','IP2',Edit2.Text);
ini.Free;
end;
在FormCreate中OpenIni,在FormClose中SaveIni。