Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Inherit forms Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Oct-02
Category
VCL-Forms
Language
Delphi All Versions
Views
70
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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   var
4     DummyForm: TForm0; {Ancestor form}
5     f: integer;
6     tempComp: TComponent;
7   begin
8     try
9       DummyForm := TForm0.Create(Application);
10      for f := DummyForm.ComponentCount - 1 downto 0 do
11      begin
12        {See if the component exists in the descendant form}
13        tempComp := FindComponent(DummyForm.Components[f].Name);
14        if not Assigned(tempComp) then
15        begin
16          {Doesn't exist so move it}
17          tempComp := DummyForm.Components[f];
18          DummyForm.RemoveComponent(tempComp);
19          InsertComponent(tempComp);
20          if tempComp is TControl then
21            with tempComp as TControl do
22              if Parent = DummyForm then
23                Parent := Self;
24        end;
25      end;
26      {Override form properties here}
27      {WriteComponentsResFile('unit.dfm, Self)}- - - > {Uncommenting this will update
28  		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    finally
31      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.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC