delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Save and Restore Size and Position of your formComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
using the registry
Product:
Delphi 7.x (or higher)
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
12/07/2008
Search Keys:
delphi delphi3000 article borland vcl code-snippet form enhancement using the registry save and restore form
Times Scored:
5
Visits:
1767
Uploader: Frank de Hell
Company:
Reference: http://www.superliegebeest.nl/delphi.php#6
Component Download: http://www.superliegebeest.nl/d7/srf.zip
 
Question/Problem/Abstract:
Save and Restore Size and Position of your form using the Registry. For ease of testing I have enclosed a way to easily restart the application by clicking on the form anywhere, to make this happen I had to add Shellapi to the uses clausule. And to create this version the Registry was added to the users clausule
Answer:



Fixed a bug!

There is a different version of this project which makes use of an inifile instead, for ease of reading I created an additional download for it.

There are many more things possible with Delphi than one can make up from the poor help files that accompany it. There is virtually no conceptual help available from the standard help file, and that is just what can be so helpful for programming! I always try to not use any 3rd party component, so I can publish my stuff where and how I like it. Do not use 3rd party components if you do not have to, apart from the fact that doing it yourself gives much more satisfaction!

Save and Restore Size and Position of your form using the registry. For ease of testing I have enclosed a way to easily restart the application by clicking on the form anywhere, to make this happen I had to add Shellapi to the uses clausule. And to create this version the Registry was added to the users clausule



------------------------------------------------------------------
Project1.dpr
------------------------------------------------------------------
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
------------------------------------------------------------------


------------------------------------------------------------------
Unit1.dfm
------------------------------------------------------------------
object Form1: TForm1
  Left = 198
  Top = 116
  Width = 400
  Height = 480
  Caption = 'SRForm Size and Position using Reg'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClick = FormClick
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object lbl1: TLabel
    Left = 130
    Top = 213
    Width = 133
    Height = 26
    Caption = 'Click to test'#13#10'[application will restart]'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
end
------------------------------------------------------------------



------------------------------------------------------------------
Unit1.pas
------------------------------------------------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Registry, Shellapi, StdCtrls;

type
  TForm1 = class(TForm)
    lbl1: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure ReadFromRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
    R.RootKey := HKEY_CURRENT_USER;
    if R.OpenKey('\Software\fdehell\srf', True) then
    begin
    Form1.left:=R.ReadInteger('left');
    Form1.top:=R.ReadInteger('top');
    Form1.height:=R.ReadInteger('height');
    Form1.width:=R.ReadInteger('width');
    end;
Finally
R.CloseKey;
R.Free;
end;
end;


procedure WriteToRegistry;
var
R : TRegistry;
begin
R := TRegistry.Create;
try
    R.RootKey := HKEY_CURRENT_USER;
    if R.OpenKey('\Software\fdehell\srf', True) then
    R.WriteInteger('left',Form1.Left);
    R.WriteInteger('top',Form1.Top);
    R.WriteInteger('height', Form1.Height);
    R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
R : TRegistry;
begin
R := TRegistry.Create;
try
    R.RootKey := HKEY_CURRENT_USER;
    if R.OpenKey('\Software\fdehell\srf', True) then
    R.WriteInteger('left',Form1.Left);
    R.WriteInteger('top',Form1.Top);
    R.WriteInteger('height', Form1.Height);
    R.WriteInteger('width', Form1.Width);
Finally
R.CloseKey;
R.Free;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ReadFromRegistry;
end;

procedure TForm1.FormClick(Sender: TObject);
var
  AppName : PChar;
begin
  AppName := PChar( Application.ExeName );
  ShellExecute( Handle, 'open', AppName, nil, nil, SW_SHOWNORMAL );
  close;
end;


end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Site is down see my new site
    Nullified van Bommel (Aug 12 2010 12:46AM)

This site was shut down sadly, use my new site please http://www.delphi7.nl or please respond to my emails staff?
Respond

Hmm
    2urgen - (Dec 21 2008 10:13PM)

You forgot WindowState.

Respond

RE: Hmm
Frank de Hell (Dec 23 2008 9:47PM)

Well ok, that can happen, but then pls reply constructive, like send in the corrected code pls, thank you!
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
L. Rosenstein
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)