可参考: var faceIni: TIniFile; begin faceini:=TIniFile.Create(ExtractFileDir(Application.ExeName)+'\Position.ini'); Top:=faceIni.ReadInteger('Pos','Top','10'); Left:=faceIni.ReadInteger('Pos','Left','10'); end;
用这个记住窗口关闭时的位置和大小 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var mypath : string; begin mypath := extractfilepath(application.ExeName); showmessage(mypath); with tinifile.create(mypath+'form.ini') do begin //write the form positon in '.ini' file writeinteger(name,'left',left); writeinteger(name,'top',top); writeinteger(name,'width',width); writeinteger(name,'height',height); free; end; end; 用这个读上次窗口打开的位置和大小 procedure TForm1.FormCreate(Sender: TObject); var mypath : string; MyIniFile: TIniFile; newbmp:tbitmap; i,j:integer; begin mypath :=extractfilepath(application.ExeName); showmessage(mypath); myinifile:=TIniFile.Create(mypath+'form.ini'); with myinifile do begin if readinteger(name,'left',-1)=-1 then //if '.ini' file not exit begin left:=50; top:=50; end else begin left:=readinteger(name,'left',left); //read the form initial position top:=readinteger(name,'top',top); height:=readinteger(name,'height',height); width:=readinteger(name,'width',width); end; free; end; end;
var
faceIni: TIniFile;
begin
faceini:=TIniFile.Create(ExtractFileDir(Application.ExeName)+'\Position.ini');
Top:=faceIni.ReadInteger('Pos','Top','10');
Left:=faceIni.ReadInteger('Pos','Left','10');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
mypath : string;
begin
mypath := extractfilepath(application.ExeName);
showmessage(mypath);
with tinifile.create(mypath+'form.ini') do
begin //write the form positon in '.ini' file
writeinteger(name,'left',left);
writeinteger(name,'top',top);
writeinteger(name,'width',width);
writeinteger(name,'height',height);
free;
end;
end;
用这个读上次窗口打开的位置和大小
procedure TForm1.FormCreate(Sender: TObject);
var
mypath : string;
MyIniFile: TIniFile;
newbmp:tbitmap;
i,j:integer;
begin
mypath :=extractfilepath(application.ExeName);
showmessage(mypath);
myinifile:=TIniFile.Create(mypath+'form.ini');
with myinifile do
begin
if readinteger(name,'left',-1)=-1 then //if '.ini' file not exit
begin
left:=50;
top:=50;
end
else
begin
left:=readinteger(name,'left',left); //read the form initial position
top:=readinteger(name,'top',top);
height:=readinteger(name,'height',height);
width:=readinteger(name,'width',width);
end;
free;
end;
end;
补充一下,在Uses段内要加上
uses IniFiles;