const
IniFileName = 'MyApp.Ini'
//Use Windows directory
procedure TForm1.FormShow(Sender: TObject);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(IniFileName);
Top := IniFile.ReadInteger('Form1', 'Top', Top);
Left := IniFile.ReadInteger('Form1', 'Left', Left);
Width := IniFile.ReadInteger('Form1', 'Width', Width);
Height := IniFile.ReadInteger('Form1', 'Height', Height);
IniFile.Free;
if Left < 0 then Left := 0;
if Top < 0 then Top := 0;
if Width < 310 then Width := 310;
if Height <= 250 then Height := 250;
if (Left + Width) > Screen.Width then Left := Screen.Width - Width;
if (Top + Height) > Screen.Height then Top := Screen.Height -Height;
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(IniFileName);
IniFile.WriteInteger('Form1', 'Top', Top);
IniFile.WriteInteger('Form1', 'Left', Left);
IniFile.WriteInteger('Form1', 'Width', Width);
IniFile.WriteInteger('Form1', 'Height', Height);
IniFile.Free;
end;