Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi 5 Form Inheritence Problem... HELP 1

Status
Not open for further replies.

colttaylor

Programmer
Aug 20, 2002
117
US
I want to use form inheritance in a project and have set up an abstract ancestor form called tdbform. I then created a descendent form and IT WORKED!!! Cool stuff... An hour later, I had four different descendent forms, each offering a consistent interface to a different database table. Since they all were created using the "Inherit from" option of the object repository, modifications to the ancestor, enhances all four descendents at the same time. Cool!!!
Then I saved the project, closed down delphi and got some sleep.
The next morning, I launch Delphi and am told during the startup that...

Error creating form: Ancestor for 'tdbform' not found

Now the F12 key doesn't for any of the descendent forms. All of the ancestor and descendent files (.pas and .dfm ) are present in the project's subdirectory.

What is going on...?
Any help would be greatly appreciated as I am about to rewrite the whole project without inheritence.

Thanks,
Colt.

If it's stupid but it works, it isn't stupid
 
Okay, relax.

Open the project and close all forms.

Make sure the ancestor form is in the project. Open it first.

Then open the descendents.

If you still have problems, make sure the descendent are really decending from the correct class name and have the correct unit in the uses clause of the interface.

Last resort: open the DFM files of the descendents and change every "inherited" keyword to "object". This will break the connection. Any component modified in the descendent will probably be okay, but untouched components will simply dissapear.

You can also do the reverse: open a form's DFM, change "object" to "inherited"; change the class definition in the PAS file to inherit from something other than TForm or TDataModule; close them all; and open the ancestor first.

When you save a descendent, its DFM will only have its differences from its ancestor's.

I converted a lot of duplicated forms into form inheretence this way. You have to be careful about names (e.g. you can have only one "Label1", but it works.

Cheers
 
Thanks for the advice!
I tried the close everything and reopen the ancestor first with no luck.
I then tried my own idea of modifying the .dpr's uses lines to include a drive letter and complete path in the ancestor's filename. Still no luck.
I checked the declaration of the descendents as you suggested as well as their uses causes. Unfortunately Everything looks correct.

I then simplified my project, eliminating three descendents so that I have only a three forms called...
FRMMAIN (of type tfrmmain descendent of tform)
DBFORM (of type tdbform descendent of tform)
USRFORM (of type tusrform descentent of tdbform)

This simpler project also had the problem, but I was now able to see a subtle aspect I had missed before. When I open USRFORM's unit, the error reads...

Error creating form: Ancestor for 'tdbform' not found

Notice the word "for"... The ancestor for tdbform is tform. Could that be significant? So I tried changing tdbform's ancestor to anything else (I used tcustomform) to see if that would change anything. It didn't.

I'm avoiding your last suggestion because as you suggested, it breaks the connection and that defeats the purpose. I can recode the descendent forms in 30 minutes by using the object repository's copy usage type (which would have a similar effect as your last suggestion), but I have big plans for the ancestor form which have not been coded yet. So I need inheritence.

I'm going to try your suggestion now with a twist. In a copy of the project directory, I'm going to modify the descendent dfm files and sever the connection. Then once that works, I'm going to reverse the dfm changes to see if that reactivates inheritence.

Just in case that doesn't work, do you have any more suggestions? Also, any idea why the error happened? I like form inheritence, but I can only consider using it regularly if I can avoid this type of distraction and difficulty in the future. Any help you could offer is greatly appreciated.

Thanks,
Colt.

If it's stupid but it works, it isn't stupid
 
"Sometimes, Delphi gets its head wedged".

Danny Thorpe's book has some hints about how things work. That, and personal conversations, give me a little insight into how things work.

* Hey! * Check the order of creation (Project Options | Forms). Make sure that looks good. Or create a new project and add each form in order.

Cheers

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top