unit savepos; { A component for saving and restoring the last position of the form. Author: Vesa Lappalainen Date: 15.2.1998 Changes: } interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TSavePos = class(TComponent) private FIniName : string; FIniSection : string; Form : TForm; protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Loaded; override; published property IniName : string read FIniName write FIniName; property IniSection : string read FIniSection write FIniSection; end; procedure Register; implementation uses KDouble,KString,IniFiles; procedure TSavePos.Loaded; var f:TForm; Ini : TIniFile; s,Item,Section:string; begin Form := NIL; if ( csDesigning in ComponentState ) then exit; if not ( Owner is TForm ) then exit; f := Owner as TForm; Form := f; Ini := TIniFile.Create(GetIniName(IniName)); if ( Ini = NIL ) then exit; Section := IniSection; Item := f.Name; s := Ini.ReadString(Section,Item,''); f.Left := ExtractInt(s,',',f.Left); f.Top := ExtractInt(s,',',f.Top); f.Width := ExtractInt(s,',',f.Width); f.Height := ExtractInt(s,',',f.Height); Ini.Free; if ( f.Left > Screen.Width ) then f.Left := Screen.Width - 30; if ( f.Top > Screen.Height ) then f.Top := Screen.Height - 30; end; constructor TSavePos.Create(AOwner: TComponent); begin inherited Create(AOwner); IniSection := 'Pos'; end; destructor TSavePos.Destroy; var f:TForm; Ini : TIniFile; s,Item,Section:string; begin if ( csDesigning in ComponentState ) then begin inherited Destroy; exit; end; if ( Form = NIL ) then exit; f := Form; Ini := TIniFile.Create(GetIniName(IniName)); if ( Ini = NIL ) then exit; Section := IniSection; Item := f.Name; s := IntToStr(f.Left) + ',' + IntToStr(f.Top) + ',' + IntToStr(f.Width) + ',' + IntToStr(f.Height); Ini.WriteString(Section,Item,s); Ini.Free; inherited Destroy; end; procedure Register; begin RegisterComponents('Kave2000', [TSavePos]); end; end.