1 unit AppForm;
2 
3 {$mode objfpc}{$H+}
4 
5 interface
6 
7 uses
8   Classes, SysUtils, Forms;
9 
10 Type
11   TInitFormAt = (ifaShow,ifaCreate,ifaActivate);
12 
13   { TAppForm }
14 
15   TAppForm = Class(TForm)
16   private
17     FAfterInit: TNotifyEvent;
18     FBeforeInit: TNotifyEvent;
19     FInitAt: TInitFormAt;
20     Procedure InitForm;
21   Protected
22     Procedure DoInitForm; virtual;
23   Public
24     Constructor Create(AOwner : TComponent); override;
25     Procedure DoShow; override;
26     Procedure Activate; override;
27   Published
28     // New properties
29     Property InitAt : TInitFormAt Read FInitAt Write FinitAt default ifaShow;
30     Property BeforeInitForm : TNotifyEvent Read FBeforeInit Write FBeforeInit;
31     Property AfterInitForm : TNotifyEvent Read FAfterInit Write FAfterInit;
32     // TCustomForm properties that we allow to edit in the IDE.
33     // In order to edit properties in the IDE, the class must be registered
34     // via a design time package.
35     // See http://wiki.lazarus.freepascal.org/Extending_the_IDE#Forms
36     property Caption;
37     property ActiveControl;
38     property BorderStyle;
39     property Color;
40     property FormStyle;
41     property OnClose;
42     property OnCloseQuery;
43     property OnCreate;
44     property OnDeactivate;
45     property OnDestroy;
46     property OnHide;
47     property OnShow;
48     property ParentFont;
49     property PixelsPerInch;
50     property PopupMenu;
51   end;
52 
53 
54 implementation
55 
56 { TAppForm }
57 
58 procedure TAppForm.InitForm;
59 begin
60   If Assigned(BeforeInitForm) then
61     BeforeInitForm(Self);
62   DoInitForm;
63   If Assigned(AfterInitForm) then
64     AfterInitForm(Self);
65 end;
66 
67 procedure TAppForm.DoInitForm;
68 begin
69   // Do nothing yet.
70 end;
71 
72 constructor TAppForm.Create(AOwner: TComponent);
73 begin
74   inherited Create(AOwner);
75   if (InitAt=ifaCreate) then
76     InitForm;
77 end;
78 
79 procedure TAppForm.DoShow;
80 begin
81   If InitAt=ifaShow then
82     InitForm;
83   inherited DoShow;
84 end;
85 
86 procedure TAppForm.Activate;
87 begin
88   if (InitAt=ifaActivate) then
89     InitForm;
90   inherited Activate;
91 end;
92 
93 end.
94 
95