delphi INI文件操作用法


本文整理自网络,侵删。

 
unit Unit1;

interface

uses
  System.IOUtils, System.IniFiles, Winapi.Windows, Winapi.Messages, System.SysUtils,
  System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    edtName: TEdit;
    Label2: TLabel;
    rgSex: TRadioGroup;
    rbMan: TRadioButton;
    rbWoman: TRadioButton;
    Label3: TLabel;
    edtAge: TEdit;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    chk1: TCheckBox;
    chk2: TCheckBox;
    cbbAddress: TComboBox;
    Label5: TLabel;
    btnSave: TButton;
    procedure btnSaveClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ConfigPath: string;

implementation

{$R *.dfm}

procedure TForm1.btnSaveClick(Sender: TObject);
var
  IniFile: TIniFile;
  Section: string;
begin
  //配置文件
  IniFile := TIniFile.Create(ConfigPath);
  Section := 'basic';
  IniFile.WriteString(Section, 'editName', edtName.Text);
  IniFile.WriteString(Section, 'editAge', edtAge.Text);
  IniFile.WriteBool(Section, 'man', rbMan.Checked);
  IniFile.WriteBool(Section, 'chk1', chk1.Checked);
  IniFile.WriteBool(Section, 'chk2', chk2.Checked);
  IniFile.WriteInteger(Section, 'address', cbbAddress.ItemIndex);

end;

procedure TForm1.FormCreate(Sender: TObject);
var
  IniFile: TIniFile;
begin
  ConfigPath := TDirectory.GetCurrentDirectory() + '\UserConfig.ini';
  IniFile := TIniFile.Create(ConfigPath);
  edtName.Text := IniFile.ReadString('basic', 'editName', '');
  edtAge.Text := IniFile.ReadString('basic', 'editAge', '');
  rbMan.Checked := IniFile.ReadBool('basic', 'man', False);
  rbWoman.Checked := not rbMan.Checked;
  chk1.Checked := IniFile.ReadBool('basic', 'chk1', False);
  chk2.Checked := IniFile.ReadBool('basic', 'chk2', False);
  cbbAddress.ItemIndex := IniFile.ReadInteger('basic', 'address', 0);

end;

end.

相关阅读 >>

Delphi wm_copydata的应用

Delphi 秒计算分钟、小时函数

dededl安卓中保持屏幕常亮

Delphi二值图像腐蚀算法

Delphi程序中操作注册表

Delphi 6句代码实现Delphi动态调用api函数

Delphi ado通用操作数据单元

Delphi 通过wmi获取u盘硬件特征码

Delphi中move函数的正确理解

Delphi listview1 图标不齐,错乱解决方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...