Delphi Ini 操作简单例子

interface

uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls, IniFiles; //加个INIFILES单元

type
   TForm1 = class(TForm)
     Label1: TLabel;
     Label2: TLabel;
     Label3: TLabel;
     Label4: TLabel;
     Edit1: TEdit;
     Edit2: TEdit;
     Edit3: TEdit;
     Edit4: TEdit;
     Button1: TButton;
     Button2: TButton;
     procedure FormCreate(Sender: TObject);
     procedure Button2Click(Sender: TObject);
     procedure Button1Click(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
   end;

var
   Form1: TForm1;
   Myini: Tinifile;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
   Var
   FileName:string;
begin
   Myini:=Tinifile.create(ExtractFilePath(Paramstr(0))+'XMN.ini');
   Myini.WriteString('论坛','注册人数',Edit1.Text);
   Myini.WriteString('论坛','文章数量',Edit2.Text);
   Myini.WriteString('论坛','访问人数',Edit3.Text);
   Myini.WriteString('论坛','留言数量',Edit4.Text);
   Application.MessageBox('写入成功!','成功',64)
end;

procedure TForm1.Button2Click(Sender: TObject);
   Var
   Filename:String;
begin
   Myini:=Tinifile.create(ExtractFilePath(Paramstr(0))+'XMN.ini');
   Edit1.Text:=myini.ReadString('论坛','注册人数','') ;
   edit2.Text:=myini.ReadString('论坛','文章数量','') ;
   Edit3.Text:=myini.ReadString('论坛','访问人数','') ;
   Edit4.Text:=myini.ReadString('论坛','留言数量','') ;
   Application.MessageBox('读入成功!','成功',64)
end;

procedure TForm1.FormCreate(Sender: TObject);
   Var
   Filename:String;
begin
   Myini:=Tinifile.create(ExtractFilePath(Paramstr(0))+'XMN.ini');
   Edit1.Text:=myini.ReadString('论坛','注册人数','') ;
   edit2.Text:=myini.ReadString('论坛','文章数量','') ;
   Edit3.Text:=myini.ReadString('论坛','访问人数','') ;
   Edit4.Text:=myini.ReadString('论坛','留言数量','') ;
end;

end.

上一篇:Ternary Search Tree Java实现


下一篇:keras实现不同形态的模型