Delphi5 如何读/写ini文件?

hyoupeng 2001-10-08 05:20:47
我希望将某些参数存于一.ini文件中,在需要的时候再从该文件中读取,
请各位大侠告知在Delphi 5.0中如何实现。谢谢!
...全文
180 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
enlightenment 2001-10-08
  • 打赏
  • 举报
回复
uses
IniFiles;
powerlee 2001-10-08
  • 打赏
  • 举报
回复
uses 中加入 Inifiles

procedure ....
var
inifile:Tinifile;
filename:string;
begin
//建立与aa.ini的联系
inifile := Tinifile.create('aa.ini');
//从PROGRAM节读File的设置信息
filename := inifile.readstring('PROGRAM','FILE','');
//释放
INIFILE.free;
ShowMessage(filename);
end;
enlightenment 2001-10-08
  • 打赏
  • 举报
回复
//删除键值
procedure MyIni_DeleteKey(MySection,MyIdent:string);
begin
Myini:=TIniFile.Create(IniFilename);
Myini.DeleteKey(MySection,MyIdent);
Myini.Free;
end;

//删除段
procedure MyIni_EraseSection(MySection:string);
begin
Myini:=TIniFile.Create(IniFilename);
Myini.EraseSection(MySection);
Myini.Free;
end;

//读取Bool值
function MyIni_ReadBool(MySection,MyIdent:string;
MyBool:Boolean):Boolean;
begin
Myini:=TIniFile.Create(IniFilename);
Result:=Myini.ReadBool(MySection,MyIdent,MyBool);
Myini.Free;
end;

//读取Integer值
function MyIni_ReadInteger(MySection,MyIdent:string;
MyInteger:Integer):Integer;
begin
Myini:=TIniFile.Create(IniFilename);
Result:=Myini.ReadInteger(MySection,MyIdent,MyInteger);
Myini.Free;
end;

//读取字符串值
function MyIni_ReadString(MySection,MyIdent:string;
MyString:String):Pchar;
begin
Myini:=TIniFile.Create(IniFilename);
Result:=Pchar(Myini.ReadString(MySection,MyIdent,MyString));
Myini.Free;
end;

//写入Bool值
procedure MyIni_WriteBool(MySection,MyIdent:string;
MyBool:Boolean);
begin
Myini:=TIniFile.Create(IniFilename);
Myini.WriteBool(MySection,MyIdent,MyBool);
Myini.Free;
end;

//写入Integer值
procedure MyIni_WriteInteger(MySection,MyIdent:string;
MyInteger:Integer);
begin
Myini:=TIniFile.Create(IniFilename);
Myini.WriteInteger(MySection,MyIdent,MyInteger);
Myini.Free;
end;

//写入String值
procedure MyIni_WriteString(MySection,MyIdent:string;
MyString:String);
begin
Myini:=TIniFile.Create(IniFilename);
Myini.WriteString(MySection,MyIdent,MyString);
Myini.Free;
end;

chechy 2001-10-08
  • 打赏
  • 举报
回复
TIniFile

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧