uses inifile; var inifiles:Tinifile; begin inifiles:=TInifile.create(文件路径); inifiles.writestring(扇区名,字段名,写入的值);//写ini edit.text:=inifiles.readstring(扇区名,字段名,预设值);//读ini end; 读写写到一起的,自己修改一下就可以了
This example reads the Transfer section of the myapp.ini file into a memo and changes one of the strings in the INI file when Button1 is clicked. When Button2 is clicked, the myapp.ini file is restored to its initial state, using the values stored in the memo. Before you run this example, you must add the IniFiles unit to the uses clause of your unit.Warning: Do not click button2 before you have clicked button1!procedure TForm1.Button1Click(Sender: TObject);var MyIniFile: TIniFile; begin MyIniFile := TIniFile.Create('myapp.ini'); Memo1.Clear; MyIniFile.ReadSectionValues('Transfer', Memo1.Lines); if Memo1.Lines.Values['Title1'] <> 'Picture Painter' then MyIniFile.WriteString('Transfer', 'Title1', 'Picture Painter'); MyIniFile.Free; end;procedure TForm1.Button2Click(Sender: TObject);var MyIniFile: TIniFile; begin MyIniFile := TIniFile.Create('myapp.ini'); { if the entry wasn抰 there before, delete it now } if Memo1.Lines.Values['Title1'] = '' then MyIniFile.DeleteKey('Transfer', 'Title1') { otherwise, restore the old value } else MyIniFile.WriteString('Transfer', 'Title1', Memo1.Lines.Values['Title1']); MyIniFile.Free; end;
huojiehai(海天子) 也来了啊!谢谢! 有个问题,这个INI文件是自动创建的吗?只要程序运行后执行 procedure TForm1.FormCreate(Sender: TObject); var filename:string; begin filename:=ExtractFilePath(paramstr(0))+'myini.ini'; myinifile:=TInifile.Create(filename); end; 这个后myini.ini就会自动生成吗? 如果是的话,在什么地方?是程序文件夹吗?
var
inifiles:Tinifile;
begin
inifiles:=TInifile.create(文件路径);
inifiles.writestring(扇区名,字段名,写入的值);//写ini
edit.text:=inifiles.readstring(扇区名,字段名,预设值);//读ini
end;
读写写到一起的,自己修改一下就可以了
inifile.WriteString('ftp_sever','ftp_ip',trim(ftpaddress.Text));
//重新连接数据库
ser_ip:=IniFile.ReadString('sever_ip', 'sever', '');
user_name:=inifile.readstring('user_name','default_name','');
user_pw:=inifile.readstring('user_pw','default_pw','');
dbname:=inifile.readstring('dbname','database','');
ftp_ip:=inifile.readstring('ftp_sever','ftp_ip','');
inifile.free;
tanqth(青蛙) 谢谢你的资料我会仔细看看
Before you run this example, you must add the IniFiles unit to the uses clause of your unit.Warning: Do not click button2 before you have clicked button1!procedure TForm1.Button1Click(Sender: TObject);var
MyIniFile: TIniFile;
begin
MyIniFile := TIniFile.Create('myapp.ini');
Memo1.Clear;
MyIniFile.ReadSectionValues('Transfer', Memo1.Lines);
if Memo1.Lines.Values['Title1'] <> 'Picture Painter' then
MyIniFile.WriteString('Transfer', 'Title1', 'Picture Painter');
MyIniFile.Free;
end;procedure TForm1.Button2Click(Sender: TObject);var
MyIniFile: TIniFile;
begin MyIniFile := TIniFile.Create('myapp.ini'); { if the entry wasn抰 there before, delete it now }
if Memo1.Lines.Values['Title1'] = '' then
MyIniFile.DeleteKey('Transfer', 'Title1')
{ otherwise, restore the old value }
else
MyIniFile.WriteString('Transfer', 'Title1', Memo1.Lines.Values['Title1']);
MyIniFile.Free;
end;
有个问题,这个INI文件是自动创建的吗?只要程序运行后执行
procedure TForm1.FormCreate(Sender: TObject);
var
filename:string;
begin
filename:=ExtractFilePath(paramstr(0))+'myini.ini';
myinifile:=TInifile.Create(filename);
end;
这个后myini.ini就会自动生成吗?
如果是的话,在什么地方?是程序文件夹吗?