Author: Jonas Bilinkevicius
How to inherit forms
Answer:
Insert the following in the OnCreate event of the descendant form:
1 2 procedure TForm1.FormCreate(Sender: TObject);
3 var4 DummyForm: TForm0; {Ancestor form}5 f: integer;
6 tempComp: TComponent;
7 begin8 try9 DummyForm := TForm0.Create(Application);
10 for f := DummyForm.ComponentCount - 1 downto 0 do11 begin12 {See if the component exists in the descendant form}13 tempComp := FindComponent(DummyForm.Components[f].Name);
14 ifnot Assigned(tempComp) then15 begin16 {Doesn't exist so move it}17 tempComp := DummyForm.Components[f];
18 DummyForm.RemoveComponent(tempComp);
19 InsertComponent(tempComp);
20 if tempComp is TControl then21 with tempComp as TControl do22 if Parent = DummyForm then23 Parent := Self;
24 end;
25 end;
26 {Override form properties here}27 {WriteComponentsResFile('unit.dfm, Self)}- - - > {Uncommenting this will update28 the dfm file for the descentant form. Closing and then opening the form unit 29 will allow you to edit the inherited components visually}30 finally31 DummyForm.Free;
32 end;
33 end;
where TForm0 is the ancestor form.
If you wish to override a number of properties for any component, cut and paste the component in the dfm file. This will allow you to visually edit it.