龙
龙之天涯
Unregistered / Unconfirmed
GUEST, unregistred user!
unit SaveFormSize;
interface
uses
Windows, messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,Registry;
type
TSaveMode = (smPositionOnly, smSizeOnly,smAll);//三种保存模式
TSaveFormSize = class(TComponent)
private
Mode : TSaveMode ;
FCompany : String;
FProduct : String;
FSubKey : String;
FActive : Boolean;
protected
public
procedure Save;
procedure Load;
constructor Create(AOwner: TComponent);
destructor Destroy;
published
property ComPany: String read FCompany write FCompany ;
property Product: String read FProduct write FProduct ;
property SubKey: String read FSubKey write FSubKey;
property SaveMode : TSaveMode read Mode write mode;
property Active : Boolean read FActive write FActive;
end;
procedure register ;
implementation
var
Reg : TRegistry;
constructor TSaveFormSize.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Active := False;
// Reg := TRegistry.Create();
end;
destructor TSaveFormSize.Destroy;
begin
inherited Destroy;
end;
procedure register ;
begin
RegisterComponents('DYDRAW',[TSaveFormSize]);
end;
procedure TSaveFormSize.Load;
var
key : string;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Key :='SOFTWARE/';
if trim(FCompany)<>'' then key := key + FCompany;
if trim(FProduct)<>'' then key := key +'/' + FProduct;
if trim(FSubKey)<>'' then key := key +'/' + FSubkey;
if Reg.OpenKey(Key,True) then
begin
if (mode = Small) or (Mode = smPositionOnly) then
begin
if Reg.ValueExists(TForm(Owner).Name + '.Left') and (TForm(OWner).Left > 0) then
TForm(OWner).Left := Reg.ReadInteger(TForm(OWner).Name + '.Left');
if Reg.ValueExists(TForm(Owner).Name + '.Top') and (TForm(OWner).Top > 0)then
TForm(Owner).Top := Reg.ReadInteger(TForm(Owner).Name + '.Top');
end;
if (mode = smAll) or (Mode = smSizeOnly) then
begin
if Reg.ValueExists(TForm(Owner).Name + '.Width') then
TForm(OWner).Width := Reg.ReadInteger(TForm(OWner).Name + '.Width');
if Reg.ValueExists(TForm(Owner).Name + '.Height') then
TForm(Owner).Height := Reg.ReadInteger(TForm(Owner).Name + '.Height');
end;
Reg.Free;
end;
end;
procedure TSaveFormSize.Save;
var
Key : string;
begin
reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Key :='SOFTWARE/';
if trim(FCompany)<>'' then key := key + FCompany;
if trim(FProduct)<>'' then key := key +'/' + FProduct;
if trim(FSubKey)<>'' then key := key +'/' + FSubkey;
if Reg.OpenKey(Key,True) then
begin
if TForm(Owner).WindowState = wsNormal then
begin
if (mode = Small) or (Mode = smPositionOnly) then
begin
if (TForm(OWner).Left > 0) then
Reg.WriteInteger(TForm(Owner).Name + '.Left', TForm(Owner).Left);
if (TForm(OWner).Top > 0) then
Reg.WriteInteger(TForm(Owner).Name + '.Top', TForm(Owner).Top);
end;
if (mode = smAll) or (Mode = smSizeOnly) then
begin
Reg.WriteInteger(TForm(Owner).Name + '.Width', TForm(Owner).Width);
Reg.WriteInteger(TForm(Owner).Name + '.Height', TForm(Owner).Height);
end;
end;
Reg.Free;
end;
end;
end.
interface
uses
Windows, messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,Registry;
type
TSaveMode = (smPositionOnly, smSizeOnly,smAll);//三种保存模式
TSaveFormSize = class(TComponent)
private
Mode : TSaveMode ;
FCompany : String;
FProduct : String;
FSubKey : String;
FActive : Boolean;
protected
public
procedure Save;
procedure Load;
constructor Create(AOwner: TComponent);
destructor Destroy;
published
property ComPany: String read FCompany write FCompany ;
property Product: String read FProduct write FProduct ;
property SubKey: String read FSubKey write FSubKey;
property SaveMode : TSaveMode read Mode write mode;
property Active : Boolean read FActive write FActive;
end;
procedure register ;
implementation
var
Reg : TRegistry;
constructor TSaveFormSize.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Active := False;
// Reg := TRegistry.Create();
end;
destructor TSaveFormSize.Destroy;
begin
inherited Destroy;
end;
procedure register ;
begin
RegisterComponents('DYDRAW',[TSaveFormSize]);
end;
procedure TSaveFormSize.Load;
var
key : string;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Key :='SOFTWARE/';
if trim(FCompany)<>'' then key := key + FCompany;
if trim(FProduct)<>'' then key := key +'/' + FProduct;
if trim(FSubKey)<>'' then key := key +'/' + FSubkey;
if Reg.OpenKey(Key,True) then
begin
if (mode = Small) or (Mode = smPositionOnly) then
begin
if Reg.ValueExists(TForm(Owner).Name + '.Left') and (TForm(OWner).Left > 0) then
TForm(OWner).Left := Reg.ReadInteger(TForm(OWner).Name + '.Left');
if Reg.ValueExists(TForm(Owner).Name + '.Top') and (TForm(OWner).Top > 0)then
TForm(Owner).Top := Reg.ReadInteger(TForm(Owner).Name + '.Top');
end;
if (mode = smAll) or (Mode = smSizeOnly) then
begin
if Reg.ValueExists(TForm(Owner).Name + '.Width') then
TForm(OWner).Width := Reg.ReadInteger(TForm(OWner).Name + '.Width');
if Reg.ValueExists(TForm(Owner).Name + '.Height') then
TForm(Owner).Height := Reg.ReadInteger(TForm(Owner).Name + '.Height');
end;
Reg.Free;
end;
end;
procedure TSaveFormSize.Save;
var
Key : string;
begin
reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Key :='SOFTWARE/';
if trim(FCompany)<>'' then key := key + FCompany;
if trim(FProduct)<>'' then key := key +'/' + FProduct;
if trim(FSubKey)<>'' then key := key +'/' + FSubkey;
if Reg.OpenKey(Key,True) then
begin
if TForm(Owner).WindowState = wsNormal then
begin
if (mode = Small) or (Mode = smPositionOnly) then
begin
if (TForm(OWner).Left > 0) then
Reg.WriteInteger(TForm(Owner).Name + '.Left', TForm(Owner).Left);
if (TForm(OWner).Top > 0) then
Reg.WriteInteger(TForm(Owner).Name + '.Top', TForm(Owner).Top);
end;
if (mode = smAll) or (Mode = smSizeOnly) then
begin
Reg.WriteInteger(TForm(Owner).Name + '.Width', TForm(Owner).Width);
Reg.WriteInteger(TForm(Owner).Name + '.Height', TForm(Owner).Height);
end;
end;
Reg.Free;
end;
end;
end.