2

Hi I am having delphi application which uses more than 100 forms. There is one form call Form B which derived from the Form A.

Unit B 

interace

uses A;

Type
Form B = Class(Form A)

End;

Now, when i try to open Form B on the IDE i m getting the error, "Error cerating form: Ancestor for TFormA not found". But when i open Form A and then try to form B then i am able to open form without any error. I am not able to find why its happening. Am i missed something?

5
  • 1
    Did you use IDE to inherit FormB from FormA, or just did it manually? Commented Aug 10, 2012 at 15:50
  • SO you are using form inheritance. Two items to keep in mind. The dfm file needs to have the declaration "inherited TFormB" instead of "object TFormB" The other item is Delphi needs to know where TFormA is located before it can create TFormB. It's been a while since I have done this and if I remember correctly, it works better when the base form has been added to the repository. Commented Aug 10, 2012 at 15:52
  • @serg: no just did it manually. Commented Aug 10, 2012 at 15:54
  • @GDF: yes i am using the inheritance Commented Aug 10, 2012 at 15:55
  • Since you point out you did it manually, make sure you open both forms. Then view TFormB as text, and change it to inherited like I described in my first comment. Gonna wrap the 2 comments into an answer post Commented Aug 10, 2012 at 15:58

3 Answers 3

2

Two items to keep in mind when using form inheritance. The dfm file needs to have the declaration "inherited TFormB" instead of "object TFormB" The other item is Delphi needs to know where TFormA is located before it can create TFormB. It's been a while since I have done this and if I remember correctly, it works better when the base form has been added to the repository

Since you point out you did it manually make sure that the declaration in the dfm is using the word "inherited" instead of "object" as I described above. To make the change yourself do the following

1) open both forms. 2) Then view TFormB as text 3) Change it to inherited like described below

    inherited FormB: TFormB
      Caption = 'FormB'
      PixelsPerInch = 96
      TextHeight = 13
    end

// not

    object FormB: TFormB
      Caption = 'FormB'
      PixelsPerInch = 96
      TextHeight = 13
    end
Sign up to request clarification or add additional context in comments.

3 Comments

done the changes and saved and tried to open the form but still same problem. :(
...well I know you need the above declaration for your form inheritance to work correctly... and I know the IDE needs to be aware of the ancestor, and load it before it can load your descendant... I'm at a bit of a lose as to what to do next. You may just need to rename your form, try creating a new inherited form using the IDE, and copy your components and code in. The IDE form inheritance mechanism should accomplish what you may be missing. I would back up my work and try that next, see if it fixed the issue.
@Naren - Does your project file include unit in 'unit.pas' {FormA}?
1

You should use visual form inheritance provided by Delphi IDE; I have no Delphi 5, in Delphi XE it is accessed by File->New->Other...->Inheritable Items. I am sure it is available in Delphi 5 too, but probably from a different menu item

1 Comment

In Delphi 7 e.g. it's on a tab sheet named as a current project.
0

I had the same problem despite everything being "inherited" in the DFM file.

What fixed my problem was adding the ancestor file to the project by right-clicking in the project manager -> add and selecting the ancestor file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.