I have a problem (with sample project).
I have a TDataModule derived class to which I have added some properties and methods.
I wanted to make sure that it was possible to create a new instance of this class with a wizard similar to the one for TDataModules and also that it was possible to see the properties I added in the object inspector.
So I created the wizard and everything works fine.
The problem arises when, in an FMX project (if the project is VCL everything is fine), I add a new instance of this new class (with the wizard) then I try to inherit a further new derived class from this (visual form inheritance), I get the following error: “Error creating form in Unit3.fmx: FMX datamodules not supported.”
After much testing and research (and disturbing many friends) I came to the conclusion that the IDE does not recognize that you are inheriting from a TDataModule (indirectly) and behaves as if you were inheriting a new form, in fact it tries to create a file *.fmx instead of a *.dfm as is usually the case for DataModules even if the project is FireMonkey.
I have already verified that the pseudo property “ClassGroup” which determines the “affinity” of the DataModule to the VCL or FMX has nothing to do with this problem and neither does my code within my class derived from TDataModule so I believe that the the only two possibilities are:
-
My wizard is not suitable for the creation of a TDataModule (derivative) in FMX projects, but the creation of the instance with the wizard itself works perfectly and in VCL projects there are no problems even inheriting
-
Delphi’s IDE somewhere has to discriminate whether you are creating a Form or a DataModule and this “mechanism” has some problems with classes derived from TDataModule, as if the recognition that it is a DataModule was “hard- coded.”
So I ask anyone who can help me if you know a solution or work-around that is not manually editing the generated files (I already do that).
I created a minimal project from which I eliminated everything superfluous but complete with wizard, it allows you to verify the problem and maybe study it a little.
You can download it here: github.com/mauriziodm/MyDataModule.git
Proceed like this:
- Open the “MyDataModuleDT.dproj” project, do the build and then click on “Install” to install the generated package (wizard) in the IDE.
- Add the path where the source files are located in Delphi’s “Tools”.
- Create a new FMX project and save it somewhere
- Add a new TMyDataModule to the project (File > New > Other > MyDM > MyDataMule) and save
- Inherit from the MyDataModule added in step 4 (File > New > Other > Inheritable Items > MyDataModule2 (or the name you chose)), the error appears.
Maurizio Del Magno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I inform you that, thanks to the contribution of Claudio Piffer, the problem has been solved.
Claudio tried to modify the ‘GetAncestorName’ method so that it returns the ‘DataModule’ value, in this way he informs the IDE of the fact that albeit indirectly (in my real case) the class is a DataModule and everything seems to work.
Even though in my real case the class does not derive directly from TDataModule it seems to work well without compromising anything else.
I had tried to do the same thing but modifying the value of a constant only that this, as well as in the indicated method, was also used elsewhere and then generated problems elsewhere, instead returning that value permanently without modifying anything else elsewhere everything is fine.
Now, in my real case the method is like this:enter image description here
Maurizio Del Magno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1