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使用json解析调用淘宝ip地址库rest api 示例

Delphi的窗体文件(dfm)文件中的汉字提取出来?

使用rad studio为安卓内置的java库

indy 中idhttp元件出现http status 302错误

Delphi中让图片大小随timage控件大小变化

Delphi vclzip实现分卷压缩

Delphi firedac 下的 sqlite [7] - 备份、优化、事务(transaction)

Delphi的tclientsocket组件和tserversocket组件(c/s)说明

Delphi httpresponsestrings

Delphi-adoquery查询、插入、删除、修改

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



打赏

取消

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

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

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

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

评论

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