Mega Code Archive

 
Categories / Delphi / OOP
 

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