unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, [这里必须引用inifiles],StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var ok:tinifile;
begin
ok:=tinifile.Create('ok.ini');
ok.WriteString('form','caption',edit1.text);
ok.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var ok:tinifile;
begin
ok:=tinifile.Create('ok.ini');
form1.Caption:=ok.ReadString('form','caption','');
ok.free;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, [这里必须引用inifiles],StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var ok:tinifile;
begin
ok:=tinifile.Create('ok.ini');
ok.WriteString('form','caption',edit1.text);
ok.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var ok:tinifile;
begin
ok:=tinifile.Create('ok.ini');
form1.Caption:=ok.ReadString('form','caption','');
ok.free;
end;
end.
该博客展示了在Windows环境下,使用Delphi编写的窗体程序对INI文件进行读写操作的代码。通过按钮点击事件,实现将编辑框文本写入INI文件,以及从INI文件读取内容设置窗体标题。
641

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



