unit frm_IniOp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,INIFiles, StdCtrls, XPMan;
type
TFrmInfo = class(TForm)
GbxInfo: TGroupBox;
LblName: TLabel;
EdName: TEdit;
LblBornDate: TLabel;
EdBornDate: TEdit;
LblDoWorker: TLabel;
EdDo: TEdit;
LblPhone: TLabel;
EdPhone: TEdit;
LblHome: TLabel;
EDHome: TEdit;
BtnChange: TButton;
BtnClose: TButton;
BtnNext: TButton;
BtnDel: TButton;
procedure BtnDelClick(Sender: TObject);
procedure BtnNextClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BtnChangeClick(Sender: TObject);
procedure BtnCloseClick(Sender: TObject);
private
dir:String;
{ Private declarations }
public
{ Public declarations }
end;
var
FrmInfo: TFrmInfo;
i:integer;
implementation
{$R *.dfm}
procedure TFrmInfo.FormShow(Sender: TObject); //读取关键字
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'/MyInfo.INI');
try
EdName.Text:=iniInfo.ReadString('PersionInfo1','Name','');
EdBornDate.Text:=iniInfo.ReadString('PersionInfo1','BornDate','');
EdDo.Text:=iniInfo.ReadString('PersionInfo1','Work','');
EdPhone.Text:=iniInfo.ReadString('PersionInfo1','Phone','');
EDHome.Text:=iniInfo.ReadString('PersionInfo1','Home','');
Finally
freeAndNil(IniInfo);
end;
end;
procedure TFrmInfo.FormCreate(Sender: TObject); //读取当前目录
begin
i:=1;
getdir(0,dir);
end;
procedure TFrmInfo.BtnChangeClick(Sender: TObject); //存储关键字
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'/MyInfo.INI');
if (edName.Text<>'') and (edBornDate.Text<>'') and (edDo.Text<>'') and (EDPhone.Text<>'') and (edHome.Text<>'') then
begin //当不是空记录时,可以修改,保存。
try
iniInfo.WriteString('PersionInfo'+inttostr(i),'Name',EdName.Text);
iniInfo.WriteString('PersionInfo'+inttostr(i),'BornDate',EdBornDate.Text);
iniInfo.writeString('PersionInfo'+inttostr(i),'Work',EdDo.Text);
iniInfo.WriteString('PersionInfo'+inttostr(i),'Phone',EdPhone.Text);
iniInfo.WriteString('PersionInfo'+inttostr(i),'Home',EDHome.Text);
Finally
freeAndNil(IniInfo);
end;
end
else
showmessage('不能为空。');
end;
procedure TFrmInfo.BtnCloseClick(Sender: TObject); //关闭
begin
Close;
end;
procedure TFrmInfo.BtnNextClick(Sender: TObject); //下一条记录
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'/MyInfo.INI');
i:=i+1;
try
EdName.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Name','');
EdBornDate.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'BornDate','');
EdDo.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Work','');
EdPhone.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Phone','');
EDHome.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Home','');
Finally
freeAndNil(IniInfo);
end;
end;
procedure TFrmInfo.BtnDelClick(Sender: TObject); //删除记录
var
iniinfo:TIniFile;
begin
iniInfo:=TInIFile.Create(dir+'/MyInfo.INI');
iniinfo.EraseSection('PersionInfo'+inttostr(i));
i:=i-1;
try
EdName.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Name','');
EdBornDate.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'BornDate','');
EdDo.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Work','');
EdPhone.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Phone','');
EDHome.Text:=iniInfo.ReadString('PersionInfo'+inttostr(i),'Home','');
Finally
freeAndNil(IniInfo);
end;
end;
end.