Jump to content
Incus J

Unable to open previously saved Data Module unit

Recommended Posts

Posted (edited)

I'm struggling to open a previously saved Data Module unit that is part of an FMX project.  The module contains an FMX TActionList.  

 

When I attempt to open the project, the IDE automatically adds two extra VCL units onto the module's uses statement, like this:

uses
  System.SysUtils, System.Actions, FMX.ActnList,
  FMX.Dialogs, FMX.StdActns, System.Classes,
  Vcl.StdActns, Vcl.ActnList;

...even though it's an FMX Action List.  I don't know why it is adding those two VCL items - I can remove them manually from the uses statement, but they reappear.  If I switch from Code to Design view, the IDE protests:  "Error reading actionname.Text: Property Text does not exist" (with options to Ignore/Cancel/Ignore All).  If I choose Ignore All, the Text property is stripped from all my existing actions, and replaced with an empty Caption property.

 

It seems to be a bit confused - as though it is reading the FMX Actions and ActionList from the .dfm file, but then attempting to instantiate them as VCL Actions instead.  I'm aware that there is a ClassGroup property for Data Module units, and wonder if this has not been saved?  Note that everything was working OK prior to closing the project and then re-opening it.

 

How might I resolve this, as the IDE seems to corrupt the unit every time I open it (though I can revert using History), and as a result the project no longer compiles?

Edited by Incus J

Share this post


Link to post

Could it be that you open the datamodule while a VCL project is open? Usually the IDE stores the used framework in the project file.

Share this post


Link to post
Posted (edited)

Only this one project open.  As a quick test I've also tried opening it up in an earlier version of Delphi (10.4.1) and got the same behaviour.  The main application form seems OK.  Just this one Data Module unit is getting misinterpreted as VCL.

 

I'd like to try setting the unit's ClassGroup property (but without opening the unit, since by then it's too late).  If I've understood how Data Module's work, ClassGroup determines whether the module supports FMX or VCL controls.  Supported values are: System.Classes.TPersistent (Framework neutral), Vcl.Controls.TControl, FMX.Controls.TControl.  I'm guessing I'd want the latter.

 

There's no mention of a ClassGroup property in the text of the module's .dfm file at present (is that normal?) - but could I add it manually with a text editor somehow?  I'd need to figure out where to insert it, and ensure I get the formatting correct though.

Edited by Incus J

Share this post


Link to post
Posted (edited)

OK the ClassGroup property does not seem to be stored in the .dfm file.  There's something special about this property - documentation describes it as a pseudo-property.  Instead the assigned value is stored as a declaration in the accompanying .pas file:

{%CLASSGROUP 'FMX.Controls.TControl'}

So I think the IDE should be able to determine from that declaration that the controls on the data module are FMX.  But it's not doing.  I must have overlooked something.

Edited by Incus J

Share this post


Link to post
Posted (edited)

Oh - I can reproduce this issue in a clean empty project:

 

- Create a new FMX project with a single main form.

- Add a new datamodule unit to the project.

- Next add a non-visual FMX TActionList to the datamodule, and also add a TAction for good measure.

- Save the project, Close All, then reopen the project, and open the datamodule in the editor.

 

No problems so far.  Now in the data module .pas file, I add a single item to the implementation uses statement, like this:

implementation uses FMX.Dialogs;

{%CLASSGROUP 'FMX.Controls.TControl'}

I've added FMX.Dialogs here, but it can be any unit.

 

- Save, Close All, then reopen the project, and try to open the datamodule = Boom!

 

As soon as the implementation section gets a uses statement, the {%CLASSGROUP} pseudo-property is no longer read by the IDE when opening the module (?).  As a result the datamodule gets misinterpreted as VCL (?)

 

Or maybe I'm just really tired.  Can anyone confirm?

 

Edited by Incus J

Share this post


Link to post

The IDE places the uses clause after the CLASSGROUP entry when using Alt-F11. While the compiler may ignore it, it seems to matter for the IDE.

  • Thanks 1

Share this post


Link to post

You're correct - I'd never have thought to sandwich the CLASSGROUP between implementation and uses:

implementation

{%CLASSGROUP 'FMX.Controls.TControl'}

uses FMX.Dialogs;

...this works.  Thank you!

 

Seems strange, but do you think this is by design (working as intended) ?

 

Share this post


Link to post
16 minutes ago, Incus J said:

do you think this is by design (working as intended)

Probably more something like an incomplete spec.

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

×