Delphi XE5如何读写INI文件

首先
uses 
inifiles

然后写文件

  1. procedure THolidaySet.Button2Click(Sender: TObject);

  2. var

  3.   IniFile:TIniFile;

  4.   Count:Integer;

  5. begin


  6.   try

  7.     IniFile:=TIniFile.Create(TPath.GetHomePath+'\HolidayRobot.ini');

  8.     Count:=IniFile.ReadInteger('Config','Count',0);

  9.     Count:=Count+1;


  10.     IniFile.WriteString('Holiday'+IntToStr(Count),'TEL',Edit1.Text);

  11.     IniFile.WriteString('Holiday'+IntToStr(Count),'NAME',Edit2.Text);

  12.     IniFile.WriteString('Holiday'+IntToStr(Count),'DATETIME',CalendarEdit1.Text);

  13.     IniFile.WriteString('Holiday'+IntToStr(Count),'CONTENT',Edit4.Text);


  14.     IniFile.WriteInteger('Config','Count',Count);

  15.   finally

  16.     FreeAndNil(IniFile);

  17.   end;

  18. end;

复制代码


读INI文件

  1. procedure TForm1.FormShow(Sender: TObject);

  2. var

  3.   IniFile:TIniFile;

  4.   Count:Integer;

  5.   I:Integer;

  6. begin

  7.   try

  8.     IniFile:=TIniFile.Create(TPath.GetHomePath+'\HolidayRobot.ini');

  9.     Count:=IniFile.ReadInteger('Config','Count',0);


  10.     for I := 1 to Count do

  11.     begin

  12.       Memo1.Lines.Add(inifile.ReadString('Holiday'+IntToStr(I),'TEL',''));

  13.     end;

  14.   finally

  15.     FreeAndNil(IniFile);

  16.   end;

  17. end;


复制代码










本文转自鹅倌51CTO博客,原文链接: http://blog.51cto.com/kaixinbuliao/1575948,如需转载请自行联系原作者





上一篇:如何在Ubuntu 16.04和Fedora 22-24上安装最新的XFCE桌面?


下一篇:一个简单有趣的微信聊天机器人