Class TDynaForm (unit Unit1)

Inherits from

TForm

****************************************************************************** DynaForm Form Template for dynamic forms. © 1995 Objective Software Technology Pty Ltd. Publishers of ABC for Delphi and other fine Delphi tools. Email 100035.2441@compuserve.com Fax +61 6 2732100 Phone +61 6 2732100 ******************************************************************************** Purpose: This template allows AUTOMATIC configuration of user changes to forms, without needing any additional code to save/restore changed properties. It automatically saves/restores all published form properties and owned components at runtime using a resource file external to the exe program. So for example, all published properties such as size, position, color, fonts etc are automatically saved. In addition, any additional components created at runtime are also saved and then restored. How to Use: 1. Open this form file. 2. Save it as a template using Options|Gallery|{form templates tab}|{Add Button} 3. When creating a new form using the template, edit the constant named DefaultResFile that is defined at the start of the implementation section. A unique resource file must be provided for each form class. 4. The resource file(s) will then be automatically restored/saved each time the form(s) are created/destroyed at runtime. 5. No dialogs are currently provided for customising form properties. You will need to design these to your own requirements. Public Properties Defined in This Template: ResFile: TFileName Set in the OnCreate event to specify the name of the file to restore/save properties. NoRestore: Boolean Set to true in the OnCreate event to disable restore action. NoSave: Boolean Set to true to disable save action. OnRestore: TNotifyEvent This event occurs immediately after the form has been restored from the resource file. Set in the OnCreate event to specify the event procedure to execute. OnSave: TNotifyEvent This event occurs immediately before the form is saved. Caveats/Restrictions: 1. This file is distributed as limited freeware. If you use it, please retain the copyright message in your code. Please notify us of any suggestions or changes that may be of use to other developers so we can incorporate them in a future distribution. 2. If you want to use multiple instances of a form class, use code in the OnCreate event to assign a unique name to the resource file for each instance, or disable the form saving with the NoSave property. 3. If the form's OnCreate event changes any published properties of the form, or if it modifies any components owned by the form, then it should be executed again as the OnRestore event. To do this, assign the OnChange event to OnRestore within the OnCreate procedure, i.e. OnRestore := OnCreate(self); 4. Data in these resource files is streamed using the same mechanism Delphi uses to read/write DFM files. The files are written in binary format and cannot be edited as text. 5. When designing and debugging a form in the Delphi IDE, it is necessary to disable the save function or delete the resource file each time the form is edited. Otherwise design changes appear to be lost at runtime, when the old resource is restored. 6. Avoid using the file suffix *.DFM for resource files otherwise your delphi project could be inadvertantly overwritten.

Constructors


constructor Create(AOwner: TComponent);

Edit this constant to set a static file name for instances of this form.


Functions

procedure Button1Click(Sender: TObject);


procedure Button2Click(Sender: TObject);


procedure Button3Click(Sender: TObject);


procedure Button4Click(Sender: TObject);


destructor Destroy;

Create form instance from EXE and then restore saved property values.

function GetDefaultResFile: TFileName;

nothing

procedure RestoreFromFile(AResFile: TFileName);


procedure SaveToFile(AResFile: TFileName);

Save the published form and component properties to a Res File before destroying.

Properties

property NoRestore : Boolean

also defaults to the constant declared below

property NoSave : Boolean

must be set in OnCreate event

property ResFile : TFileName

The following public properties can be set in code to change the filing behaviour - for example in OnCreate

Events

event OnRestore : TNotifyEvent


event OnSave : TNotifyEvent

must be set in OnCreate event

Variables

Button1 : TButton;


Button2 : TButton;


Button3 : TButton;


Button4 : TButton;


ColorDialog1 : TColorDialog;


Edit1 : TEdit;


Edit2 : TEdit;


Edit3 : TEdit;


Label1 : TLabel;


FNoRestore : Boolean;


FNoSave : Boolean;


FOnRestore : TNotifyEvent;


FOnSave : TNotifyEvent;


FResFile : TFileName;

Private declarations


Constructors


constructor Create(AOwner: TComponent);

Edit this constant to set a static file name for instances of this form. e.g. UNIT1.DFR If no name is specified at runtime, the template will Create/Read/Write a file of this name in the exe directory


Functions


procedure Button1Click(Sender: TObject);


procedure Button2Click(Sender: TObject);


procedure Button3Click(Sender: TObject);


procedure Button4Click(Sender: TObject);


destructor Destroy;

Create form instance from EXE and then restore saved property values. First does inherited Form Create and OnCreate event; Set the NoRestore property to True in OnCreate to disable these functions: - rereads the published form and component properties from a Res File; - executes the OnRestore event if assigned.


function GetDefaultResFile: TFileName;

nothing


procedure RestoreFromFile(AResFile: TFileName);


procedure SaveToFile(AResFile: TFileName);

Save the published form and component properties to a Res File before destroying. Set NoSave to true to disable this function.


Properties


property NoRestore : Boolean

also defaults to the constant declared below


property NoSave : Boolean

must be set in OnCreate event


property ResFile : TFileName

The following public properties can be set in code to change the filing behaviour - for example in OnCreate


Events


event OnRestore : TNotifyEvent


event OnSave : TNotifyEvent

must be set in OnCreate event


Variables


Button1 : TButton;


Button2 : TButton;


Button3 : TButton;


Button4 : TButton;


ColorDialog1 : TColorDialog;


Edit1 : TEdit;


Edit2 : TEdit;


Edit3 : TEdit;


Label1 : TLabel;


FNoRestore : Boolean;


FNoSave : Boolean;


FOnRestore : TNotifyEvent;


FOnSave : TNotifyEvent;


FResFile : TFileName;

Private declarations