delphi中ini文件操作
一,ini文件注释以‘;’开头
二,定义
1,在interface的uses节中添加inifiles;
2,var myinfile:tinifile;
3,打开ini文件
(1)myinifile:=tinifile.create('program.ini');
(2)var filename:string;
filename:=extractfilepath(paramstr(0))+'program.ini'; //0代表搜索到本项目的地址物理路径;
myinifile:=tinifile.create(filename);
//不指名路径的情况下文件会建在(c\windows目录中)
三,读取
procedure TForm2.btn2Click(Sender: TObject);
var
xiaojie:string;
guanjian:string;
begin
xiaojie:=edt1.Text;
guanjian:=edt2.Text;
if (xiaojie<>'') and (guanjian<>'') then
begin
if cbb2.ItemIndex=0 then
lbl6.Caption:=myinifile.ReadString(xiaojie,guanjian,缺省值) //缺省值代表ini不存在该关键字时返回值
else if cbb2.ItemIndex=1 then
bl6.Caption:=IntToStr(myinifile.ReadInteger(xiaojie,guanjian,0))
else if cbb2.ItemIndex=2 then
cbb1.ItemIndex:=Integer(myinifile.ReadBool(xiaojie,guanjian,False))
end;
myinifile.Free;
end;
四,写入
procedure TForm2.btn1Click(Sender: TObject);
var
xiaojie:string;
guanjian:string;
zhi:string;
zhi1:Integer;
zhi2:Boolean;
begin
xiaojie:=edt1.Text;
guanjian:=edt2.Text;
zhi:=edt3.Text;
zhi1:=StrToInt(edt4.Text);
zhi2:=Boolean(cbb1.ItemIndex);
if edt4.text<>'' then
myinifile.WriteString(xiaojie,guanjian,zhi);
if edt4.text<>'' then
myinifile.WriteInteger(xiaojie,guanjian,zhi1);
if (cbb1.ItemIndex=0) or (cbb1.ItemIndex=1) then
myinifile.WriteBool(xiaojie,guanjian,zhi2);
myinifile.Free;
end;
//当这个文件不存在时,上面语句还会自动创建ini文件
五,删除关键字
myinifile.deletekey('小节名','关键字');
六,删除小节
myinifile.erasesection('小节名');
七,小节操作
myinifile.readsection('小节名',tstring 变量); //可将指定小节中所有关键字名读取至一个字符串列表变量中;
myinifile.readsections(tstring 变量); //可将ini文件中所有小节名读取至一个字符串列表变量中去;
myinifile.readsectionvalues('小节名',tstring 变量); //可将ini文件中指定小节所有行(包括关键字,=,值)读取至一个字符串变量中去;
八,释放
myinifile.destory;
转载于:https://www.cnblogs.com/hanhan/archive/2012/04/01/2428280.html
- 点赞
- 收藏
- 分享
- 文章举报
- Delphi中读写INI配置文件操作总结
- Delphi TIniFile 类 操作ini配置文件
- delphi 对INI文件操作
- Delphi TIniFile 类 操作ini配置文件
- Delphi TIniFile 类 操作ini配置文件
- Delphi TIniFile 类 操作ini配置文件
- delphi操作ini文件
- delphi对ini的文件操作
- Delphi TIniFile 类 操作ini配置文件
- DELPHI操作INI文件详细讲解
- Delphi 中对 ini 文件操作
- delphi操作ini文件
- Delphi TIniFile 类 操作ini配置文件
- Delphi 中对 ini 文件操作
- 操作ini文件
- c++ Boost 对INI文件处理操作
- INI 文件的操作
- ini文件操作
- Delphi 创建目录及写日志文件、写INI文件
- INI文件的操作