DelphiFAQ Home Search:

How to change existing forms' ancestor types

 

comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

Question:

I have a project with quite a few forms, all derived from TForm. What I would like to do is create a TBaseForm (derived from TForm), put some common functionality in it, and have all my other forms
derive from TBaseForm rather than TForm.

I've tried to do this by simply using a text editor (outside of Delphi) to change the class of the form to TBaseForm, but this seems to have no effect (it even compiles ok, but doesn't inherit the
'middle' form).

How can I do this without building all my forms from the gound up?


Answer:

In the code for your form change the =class(TForm) line so it is what you want
e.g. =class(TBaseForm)

Then right-click on your form and choose 'View as Text'. You are viewing the DFM file now. The top line will look like

object Form1: TForm1

change the 'object' to 'inherited' and you're all set.

inherited Form1: TForm1

Comments:

2007-04-17, 06:39:09
anonymous from Mexico  
rating
Cool!, exactly just what I was looking for!

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.