Jump to content
Sonjli

Error creating form: Ancestor for 'TMyDataModule' not found

Recommended Posts

Hi all,

I perfectly know the error in subject. It is due of an ancestor form\datamodule missing in the project (don't go deep in all other sub-cases this error can happen...).

In my dpr I have all of the ancestors, and if I open them in IDE in the correct order (grandfather - father - child) everything is fine. BUT if I open only a "child" then this error happens.

My project is a bit complicated (I make use of injection, threads, etc.) but this simple error is making me and my team crazy.

 

Any idea how to solve this situation?

 

The object tree is something like:

TBaseDatamodule

|- TChildDatamodule

|-- TConcreteDatamodule

 

Thanks in advance,

Eddy

Share this post


Link to post

https://stackoverflow.com/questions/4518521/delphi-how-to-get-rid-of-ancestor-of-tmyform-not-found-error

 

TL;DR

Make sure all data modules (and forms) are declared in the DPR uses list on the form:

<unit name> in '<file name>' {<instance variable name>: <base type>},

  
e.g.

ModuleFoo in 'datamodules\ModuleFoo.pas' {DataModuleFoo: TDataModule},

 

I'm guessing this should work too:

ModuleFoo in 'datamodules\ModuleFoo.pas' {TDataModule},

 

Share this post


Link to post

Everything is exactly as you write. Every datamodule is correctly declared in dpr with path and comment.

 

Real code:

  ...
  UInterfacedDataModule in '..\..\..\Model\UInterfacedDataModule.pas' {DMInterfacedDatamodule: TDataModule},
  UDMCustomModel in '..\..\..\UDMCustomModel.pas' {DMCustomModel: TDataModule},
  UDMUniModel in '..\..\..\Model\UniModel\UDMUniModel.pas' {DMUniModel: TDataModule},
  ...

 

Share this post


Link to post
32 minutes ago, Sonjli said:

Everything is exactly as you write. Every datamodule is correctly declared in dpr with path and comment.

Then I'm afraid I can't reproduce the problem.

 

Can you attach a minimal project (just the dpr, dproj and two datamodule units) which reproduces the problem. And please state what version of Delphi you're using.

Share this post


Link to post

My dpr is not exactly canonical... so, is there any problem with IDE ancestor resolution and "strange" disposition of dpr code?

For example I have a wrapper object for "Application", so there is no standard

Application.createForm();

Application.Initialize;

Application.Run;

 

Can this be a problem?

I didn't try to make a cosole app (my apps are similar to console applications) with my datamodules, in fact... I can try

Share this post


Link to post
Guest

Why not to start debug your application the right way ?

 

If you don't have a file logger, then simply use OutputDebugString in all of you units, use it directly or with wrapper method, you also can add a directive to enable it when you need for later usage.

Use OutputDebugString in initialization and finalization in every unit ( you can also add it in the dpr file itself) , download DebugView from here https://docs.microsoft.com/en-us/sysinternals/downloads/debugview

The output messages will be captured in DebugView when your application outside the IDE debugger, while the Debugger messages ( Events windows) will capture the text, save both outsputs to text files, compare and you will find what is going wrong.

 

Such process will take 5 minutes of your time and will give you 100% accurate picture what had been changed, no matter how complicated your application is.

Share this post


Link to post
Guest

And yes i forgot to mention add it to modules constructor and destructor, i think you got the idea.

Share this post


Link to post
7 hours ago, Kas Ob. said:

Why not to start debug your application the right way ?

 

If you don't have a file logger, then simply use OutputDebugString in all of you units, use it directly or with wrapper method, you also can add a directive to enable it when you need for later usage.

Use OutputDebugString in initialization and finalization in every unit ( you can also add it in the dpr file itself) , download DebugView from here https://docs.microsoft.com/en-us/sysinternals/downloads/debugview

The output messages will be captured in DebugView when your application outside the IDE debugger, while the Debugger messages ( Events windows) will capture the text, save both outsputs to text files, compare and you will find what is going wrong.

 

Such process will take 5 minutes of your time and will give you 100% accurate picture what had been changed, no matter how complicated your application is.

Sorry @Kas Ob. but my problem is at designtime, not runtime. The problem happens in IDE.

thanks.

Share this post


Link to post

You can also check the dproj file the DesignClass and FormType values to be correct.

 

        <DCCReference Include="Unit527.pas">
            <Form>DataModule527</Form>
            <FormType>dfm</FormType>
            <DesignClass>TDataModule</DesignClass>
        </DCCReference>

 

Share this post


Link to post
3 hours ago, Uwe Raabe said:

You can also check the dproj file the DesignClass and FormType values to be correct.

 


        <DCCReference Include="Unit527.pas">
            <Form>DataModule527</Form>
            <FormType>dfm</FormType>
            <DesignClass>TDataModule</DesignClass>
        </DCCReference>

 

Ciao Uwe,

I try asap... never touched the dproj :B

thanks

Share this post


Link to post
2 hours ago, Lars Fosdal said:

What about registering the base form?

Open form, right click, register

sorry... what!? I have the register only on frames, not on TdataModules, am I wrong?

Share this post


Link to post
3 hours ago, Uwe Raabe said:

You can also check the dproj file the DesignClass and FormType values to be correct.

 


        <DCCReference Include="Unit527.pas">
            <Form>DataModule527</Form>
            <FormType>dfm</FormType>
            <DesignClass>TDataModule</DesignClass>
        </DCCReference>

 

Ok,I tried but they are all ok...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×