Forms Delphi

Title: Adding Custom Properties to Delphi Forms; Overriding the Create Constructor
The OnCreate event for Delphi forms (and data modules) gets fired when the the form is created. For dynamically created forms (those not listed in the Project - Options - Auto-create Forms list) the creation is controlled by your code - by calling the Create constructor.
A Delphi form can be dynamically created using either Appliction.CreateForm(TFormClass, FormName) or FormName := TFormClass.Create(Owner). When the form is created its OnCreate event is fired.
In most cases, you place initialization code in the OnCreate event handler.
Custom Property
If you need to add a custom property to a form and have it initialized *before* the OnCreate event, you will need to override the form's constructor.
If, for example, you need to override the constructor of Delphi form to initialize your own added form's property, here's what to do:
Define the property for the form,
Override the Create constructor,
Initialize your property before calling "inherited Create;"
Use your initialized property in the form's OnCreate event handler.
interface

type
TRunTimeForm = class(TForm)
procedure FormCreate(Sender: TObject) ;
private
fMyPreCreateValue: boolean;
public
constructor Create(AOwner: TComponent) ; override;
property MyPreCreateValue : boolean read fMyPreCreateValue;
end;

implementation

constructor TRunTimeForm.Create(AOwner: TComponent) ;
begin
fMyPreCreateValue := true;
inherited Create(AOwner) ;
end;

procedure TRunTimeForm.FormCreate(Sender: TObject) ;
begin
// MyPreCreateValue was initialized before the form was created!
ShowMessage(BoolToStr(MyPreCreateValue,true)) ;
end;

Note: you can not use any code that references the form's "standard" properties or any methods / properties for components owned by the form before calling "inherited create". You, however, *can* initialize your own fields (properties) as we did above.