Monday, January 08, 2007
FormMemoryReg
Guarda en el registre la posició i tamany del formulari, per recuperar-les al tornar-lo a crear.
unit FormMemoryReg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Registry, Menus;
type
//save dimensions by form name
TFormMemoryReg = class(TComponent)
private
{ Private declarations }
RegIniFile: TRegIniFile;
FOwner: TForm;
AN: string;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Loaded; override;
published
{ Published declarations }
end;
procedure Register;
implementation
constructor TFormMemoryReg.Create(AOwner: TComponent);
var
filename: string;
fl: TStringList;
begin
inherited Create(AOwner);
FOwner := TForm(AOwner);
end;
procedure TFormMemoryReg.Loaded;
var
fl: TStringList;
begin
inherited Loaded;
AN := ExtractFileName(Application.ExeName);
AN := ChangeFileExt(AN,'');
if not (csDesigning in ComponentState) then
begin
RegIniFile := TRegIniFile.Create('');
RegIniFile.RootKey := HKey_Local_Machine;
if not RegIniFile.OpenKey('Software\CompDelphi\'+AN+'\FormsMem',False) then
begin
RegIniFile.CreateKey('Software\CompDelphi\'+AN+'\FormsMem');
end;
FOwner.Top := RegIniFile.ReadInteger('',FOwner.Name+'t',FOwner.Top);
FOwner.Left := RegIniFile.ReadInteger('',FOwner.Name+'l',FOwner.Left);
FOwner.Height := RegIniFile.ReadInteger('',FOwner.Name+'h',FOwner.Height);
FOwner.Width := RegIniFile.ReadInteger('',FOwner.Name+'w',FOwner.Width);
RegIniFile.Free;
end;
end;
destructor TFormMemoryReg.Destroy;
begin
if not (csDesigning in ComponentState) then
begin
if FOwner.WindowState=wsNormal then
begin
RegIniFile := TRegIniFile.Create('');
RegIniFile.RootKey := HKey_Local_Machine;
RegIniFile.OpenKey('Software\CompDelphi\'+AN+'\FormsMem',False);
RegIniFile.WriteInteger('',FOwner.Name+'t',FOwner.Top);
RegIniFile.WriteInteger('',FOwner.Name+'w',FOwner.Width);
RegIniFile.WriteInteger('',FOwner.Name+'l',FOwner.Left);
RegIniFile.WriteInteger('',FOwner.Name+'h',FOwner.Height) ;
end;
RegIniFile.Free;
end;
inherited;
end;
procedure Register;
begin
RegisterComponents('Components Delphi', [TFormMemoryReg]);
end;
end.