I've been working on a project in Delphi 7 where I wanted to have forms inherit components from other forms. I was able to get this working, but came across the following issues (and I'm going to post the solutions to hopefully help others in the future):
First, for those who don't know how to inherit a form visually, you create the ancestor form as usual. Then go to File > New > Other. Select the tab with the name of the current project, and choose the form you want to inherit from. If you want to inherit from a form that's not part of the current project, open that form, right click it, and choose Add to Repository. Then you will be able to go to File > New > Other and select that form from the appropriate tab.
Given that, I came across issues because some of the descendant forms were already created, so I couldn't follow the process above. Also, I made some changes to forms from the standard code Delphi creates. I was able to resolve all issues with visual form inheritance using the following guidelines:
type TMyForm = class(TAncestorForm)
inherited
instead of object
, e.g.:inherited MyForm: TMyForm
var AncestorForm: TAncestorForm;
uses
section of the .dpr file of the project must have that same global variable as a comment after the unit's file name, e.g.:unAncestor in 'unAncestor.pas' {AncestorForm}
Notes/Tips:
The DPR seems a little bit trickier than that. In my case, I created an ancestor derived from TFrame. I then derived multiple frames from TAncestorFrame. My DPR's uses clause then looked like:
uses
Forms,
ancestorFrame in 'ancestorFrame.pas' {AncestorFrame : TFrame},
frame1Unit in 'frame1Unit.pas' {frame1:TFrame},
frame2Unit in 'frame2Unit .pas' {frame2:TFrame},
The DPROJ file should look like:
<DCCReference include="frame1Unit.pas">
<Form>frame1</Form>
<DesignClass>TFrame</DesignClass>
</DCCReference>
Derived Frames should look like:
TFrame1 = class(TAncestorFrame)
And Derived Frames .DFM files should say:
inherited Frame1:TFrame1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With