In prior versions of Delphi, I have used the data module (TDataModule
) as a place to keep non-visual components to avoid cluttering up the main form. In Delphi XE2, when I create a new data module, it only allows me to place database related components in it (such as TADOConnection
and TDataSource
). Why is this and how can I put other components in it? Is there an alternative?

- 26,858
- 31
- 155
- 327
-
Can you give an example of a non-visual component (one that is provided with Delphi, preferably) that it won't allow? I've never seen this problem. – Ken White Dec 31 '12 at 04:01
-
Like a `TImageList` or `TMainMenu` or `TActionManager` - When I try to paste one, it says the component class is not found, and the palette only shows database related components. – Jerry Dodge Dec 31 '12 at 04:02
-
Could it be my specific edition of RAD Studio? But then I have Enterprise, should have about everything. – Jerry Dodge Dec 31 '12 at 04:03
-
I can confirm this with `File->New->VCL Forms Application`, and then `File->New->Other->Delphi Files->Datamodule`, which leaves only the database, Intraweb, FastReports, and Indy components available in the component palette. (TImageList and TActionList are not there.) Using the Pro SKU, so it's not that causing the problem. – Ken White Dec 31 '12 at 04:15
-
Interesting, strange why this limitation would exist in the first place. The company's not ready to upgrade to XE3 quite yet, we're still settling into XE2. – Jerry Dodge Dec 31 '12 at 05:00
-
@JerryDodge can you switch to datamodule -> F6 -> type component name -> RETURN? this is weird, never had this... – Dec 31 '12 at 05:05
-
3@Ken In fact it wasn't broken in XE2. And XE3 didn't fix anything. What XE3 did was move actions out of the VCL and into a lower level and so be available to all frameworks. – David Heffernan Dec 31 '12 at 10:19
-
@David: Thanks. I was obviously wrong. :-) – Ken White Dec 31 '12 at 22:15
2 Answers
Data modules changed with the XE2 release. Remember that XE2 introduced a new component framework, FireMonkey, in addition to the long-standing VCL. A new pseudo-property, named ClassGroup
was added to data modules. This controls what components can be added to the data module in the IDE designer.
The default ClassGroup
for a data module is System.Classes.TPersistent
. This specifies that the data module is framework neutral and so accepts neither VCL components nor FMX components.
In your case you probably want to accept VCL components so you need to specify a ClassGroup
of Vcl.Controls.TControl
.
Read all about ClassGroup
in the documentation.
System.Classes.TDataModule and its descendant classes, such as Web.HTTPApp.TWebModule, have a pseudo-property named ClassGroup that does the following:
- Determines the framework affinity for the data module. That is, ClassGroup specifies that the data module is either framework-neutral or is to work with a specific framework (namely, VCL or FMX).
- Enables framework-specific nonvisual components in the Tool Palette. You need to set a framework-specific value for ClassGroup in the Object Inspector in order to enable framework-specific nonvisual components such as the following:
- TActionList is VCL-only, and so to enable TActionList in the Tool Palette, you must set ClassGroup to the VCL setting.
- TTimer exists in both FMX and VCL. To enable TTimer for the correct framework, you must set ClassGroup to either FMX or VCL, to match the framework of the parent application. (TTimer and TActionList are further discussed later in this topic.)

- 601,492
- 42
- 1,072
- 1,490
This (buggy) behavior in
unit Unit2;
interface
uses
System.SysUtils, System.Classes;
type
TDataModule2 = class(TDataModule)
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
DataModule2: TDataModule2;
implementation
{%CLASSGROUP 'System.Classes.TPersistent'}
{$R *.dfm}
end.
is caused by the line
{%CLASSGROUP 'System.Classes.TPersistent'}
To get rid of just delete or modify the line into
{.%CLASSGROUP 'System.Classes.TPersistent'}
After switch to Design
View you will see all the components as you expect.
(Delphi XE2 16.0.4504.48759)

- 18,395
- 2
- 39
- 73
-
-
PS - The hard part was figuring out how to create the data module in a way that it could be used throughout the app with common components - I wound up creating/destroying it in a try..finally block in the project's main `dpr` file, wrapping the form creation and `Run`. – Jerry Dodge Dec 31 '12 at 08:37
-
2See also http://stackoverflow.com/questions/11250019/what-does-tdatamodule-classgroup-pseudo-property-in-delphi-xe2-really-do – Jan Doggen Dec 31 '12 at 09:32
-
We have no problems in an app that was *migrated* from D2007 to XE2 (TImageList, TcxSchedulerStorage etc), but its good to know this when we add another data module. – Jan Doggen Dec 31 '12 at 09:36
-
1You can do this right inside the Object Inspector: select the datamodule and set its ClassGroup property accordingly. Then close and reopen the damodule unit. – Uwe Raabe Dec 31 '12 at 09:38
-
There's nothing buggy here. And the right solution for Jerry is to set the ClassGroup to VCL. – David Heffernan Dec 31 '12 at 10:25
-
Now that it's solved, I'm pondering why would `TPersistent` make the data module only allow database related components? How does that work? A `TComponent` is a `TPersistent`. – Jerry Dodge Dec 31 '12 at 10:41
-
It doesn't just allow database controls. It blocks VCL and FMX components. In XE3 actions are allowed because they are no longer VCL specific. And as for TPersistent. It's just a name. Thr docs make it clear what it means. – David Heffernan Dec 31 '12 at 11:00