DelphiFAQ Home Search:
General :: Programming :: Delphi :: VCL
About the Delphi VCL (Visual Component Library)

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

How to change existing forms' ancestor types

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

Generated 8:02:06 on Oct 17, 2019