uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,INIFiles;//INIFiles不要忘了加
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
With TINIFile.Create('a.ini') do//创建a.ini
begin
WriteBool('MySetting', 'CheckBox1_Checked', CheckBox1.Checked);{保存到MySetting下面的CheckBox1_Checked子键下,然后把Checkbox1的是否按下状态写进去}
WriteString('MySetting', 'Edit1_Text', Edit1.Text);//同上
end;
end;
procedure TForm1.FormCreate(Sender: TObject);//读入a.ini文件中的设置
begin
With TINIFile.Create('a.ini') do//打开已创建的a.ini
begin
CheckBox1.Checked := ReadBool('MySetting', 'CheckBox1_Checked', False);{同上面的写入一样,这里是读取ReadBool和WriteBool是两个BOOL值的写入方法.}
Edit1.Text := ReadString('MySetting', 'Edit1_Text', '');//同上
end;
end;
本文介绍了如何在Delphi应用程序中使用INI文件来保存和读取用户设置。通过TINIFile组件,实现了在FormClose事件中将CheckBox1的选中状态和Edit1的文字内容写入'a.ini'文件,而在FormCreate事件中读取这些设置,以实现配置的持久化。
4918

被折叠的 条评论
为什么被折叠?



