第一次用Delphi,主要是想完成对INI文件的读写,可是编译了之后,无错误,但是运行程序 闪了下 就没了~麻烦大家纠正下~
=============================================================================================
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,INIFiles, StdCtrls;type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject); private
{ Private declarations }
dir:String;
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}
procedure TForm2.FormShow(Sender: TObject);
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'\MyInfo.INI');
try
Edit1.Text:=iniInfo.ReadString('info','Name','');
finally
freeAndNil(IniInfo);
end;
end;
procedure TForm2.FormCreate(Sender: TObject); begin
getdir(0,dir);
end;procedure TForm2.Button1Click(Sender: TObject);
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'\MyInfo.INI');
if (edit1.Text<>'') then
begin
try
iniInfo.WriteString('info','Name',Edit1.Text);
finally
freeAndNil(IniInfo);
end;
end
else
showmessage('不能为空');
end;end.
=================================================
谢谢啦
=============================================================================================
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,INIFiles, StdCtrls;type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject); private
{ Private declarations }
dir:String;
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}
procedure TForm2.FormShow(Sender: TObject);
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'\MyInfo.INI');
try
Edit1.Text:=iniInfo.ReadString('info','Name','');
finally
freeAndNil(IniInfo);
end;
end;
procedure TForm2.FormCreate(Sender: TObject); begin
getdir(0,dir);
end;procedure TForm2.Button1Click(Sender: TObject);
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'\MyInfo.INI');
if (edit1.Text<>'') then
begin
try
iniInfo.WriteString('info','Name',Edit1.Text);
finally
freeAndNil(IniInfo);
end;
end
else
showmessage('不能为空');
end;end.
=================================================
谢谢啦
procedure TForm2.FormCreate(Sender: TObject);
var
dir: string;
a: Byte;
begin
a:= 0;
GetDir(b,dir);
end;
建议不用 getdir(0,dir);
而用extractfilepath(application.exename)+'MyInfo.INI';