Visit our Sponsor   Visit our Sponsor
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 (2)


Save and Restore Size and Position of your form...Component available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Using *.ini file
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 save-and-restore-size-and-position using-inifile form-enhancement
Times Scored:
1
Visits:
1620
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:
Updated, fixed a bug! Save and Restore Size and Position of your form using an Inifile. This form remembers the size of its window and the position on the screen, so when you restart it it restores the last width, height and x y location when you closed it. A very simple form enhancement, which you can easily write yourself!
Answer:



Updated, fixed a bug!

There is a different version of this project which makes use of the registry 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 an  Inifile.  This form remembers the size of its window and the position on the screen, so when you restart it it restores the last width, height and x y location when you closed it. A very simple form enhancement, which you can easily write yourself!

------------------------------------------------------------------
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 = 258
  Top = 172
  Width = 400
  Height = 480
  Caption = 'SRForm Size and Position using Ini'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClick = FormClick
  OnCloseQuery = FormCloseQuery
  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
    Layout = tlCenter
  end
end
------------------------------------------------------------------



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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IniFiles, StdCtrls, ShellAPI;    

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
F: TextFile;
Value: Integer;
begin
if FileExists(ChangeFileExt(ParamStr(0), '.ini')) then
begin
   AssignFile(F, ChangeFileExt(ParamStr(0), '.ini'));
   Reset(F);
   Readln(F, Value);
   Left:= Value;
   Readln(F, Value);
   Top:= Value;
   Readln(F, Value);
   Width:= Value;
   Readln(F, Value);
   Height:= Value;
   Readln(F, Value);
   WindowState:= TWindowState(Value);
   CloseFile(F);
end;
end;


procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  F: TextFile;
  Value: Integer;
begin
AssignFile(F, ChangeFileExt(ParamStr(0), '.ini'));
if (WindowState  wsNormal) and (FileExists(ChangeFileExt(ParamStr(0), '.ini')))
then
begin
   Reset(F);
   Readln(F, Value);
   Left:= Value;
   Readln(F, Value);
   Top:= Value;
   Readln(F, Value);
   Width:= Value;
   Readln(F, Value);
   Height:= Value;
   CloseFile(F);
end;
Rewrite(F);
Writeln(F, Left);
Writeln(F, Top);
Writeln(F, Width);
Writeln(F, Height);
Writeln(F, Byte(WindowState));
CloseFile(F);
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
Admins help needed
    Nullified van Bommel (Jul 28 2010 5:16PM)

My site was shut down use my new server please

http://www.delphi7.nl/sourcecode/tutorials/srform_size_and_position_using_tinifiles.php
Respond

IniFile
    Hans Pollaerts (Jan 12 2009 4:23PM)

Just wondering why you're not using TIniFile instead.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Maes
 
   














 







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