Why less components in tool palette available for datamodule than for form because of '%CLASSGROUP TPersistent'?

StackOverflow https://stackoverflow.com/questions/23270201

  •  08-07-2023
  •  | 
  •  

Question

We use SQL Direct version 6.4 in Delphi XE2 (Win7, 64-bit, but we only do 32-bit development).

I was making a new test app and found the following:

In the tool palette, when I'm on a form, there are 10 components available:

enter image description here

In the tool palette, when I'm on a datamodule, only 3 of these are available:

enter image description here

This was in a new project. I found this out when I tried to copy a TSDDatabase from another project to a datamodule in my new project.
This tells you that we have (several) other projects containing TSDDatabase (and other from the 10 minus 3) components on a datamodule, which still build and run fine.

I was actually already writing another question into SO when I noticed the following:

The datamodule I try to place a TSDDatabase contains the new

{%CLASSGROUP 'System.Classes.TPersistent'}

And the source file responsible for the component registration starts with this:

procedure Register;
begin
{$IFDEF EVAL}
  ShowReminderBox;
{$ENDIF}

{$IFDEF SD_VCL10}
    // Restrict these components to only be used with VCL components.
  GroupDescendentsWith(TSDDatabase, Controls.TControl);
  GroupDescendentsWith(TSDDataSet, Controls.TControl);
  GroupDescendentsWith(TSDSession, Controls.TControl);
  GroupDescendentsWith(TSDUpdateSQL, Controls.TControl);
{$ENDIF}

  RegisterComponents(srSQLDirect, [TSDSession, TSDDatabase, TSDQuery, TSDMacroQuery, TSDStoredProc, TSDTable, TSDUpdateSQL, TSDScript, TSDMonitor, TSDSQLBaseServer]);

  RegisterPropertyEditor(TypeInfo(Boolean), TSDDatabase, 'Connected', TSDDatabaseConnectedProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDDatabase, 'RemoteDatabase', TSDDatabaseProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDDatabase, 'SessionName', TSDSessionNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDDatabase, 'ParamsFileName', TSDFileNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDDataSet, 'DatabaseName', TSDDatabaseNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDDataSet, 'SessionName', TSDSessionNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDScript, 'DatabaseName', TSDDatabaseNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDScript, 'SessionName', TSDSessionNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDStoredProc, 'StoredProcName', TSDStoredProcNameProperty);
  RegisterPropertyEditor(TypeInfo(string),  TSDTable, 'TableName', TSDTableNameProperty);

When I removed the %CLASSGROUP statement the issue was gone.

Obviously 'grouping the descendants with' Controls.TControl together with the CLASSGROUP was the cause.

But despite looking up %CLASSGROUP pseudo-property and GroupDescendentsWith I fail to understand what that last statement does specifically.

Can anyone explain in more detail what's going on here? And specifically, how should the registration code be changed (since we have the Pro version with source, we could patch this) to prevent other colleagues wasting hours as I did? ;-)

(And: 10 minus 4 GroupDescendentsWith statements makes 6, not 3)??

Was it helpful?

Solution

Data modules are designed to be framework neutral. Which means that, with the default ClassGroup, they cannot host components that are specific to either VCL or FMX frameworks. The components that are removed when you look at the palette with a data module active are the components that are affiliated to one of those two frameworks. In this case the VCL.

The Embarcadero documentation explains this quite clearly: http://docwiki.embarcadero.com/RADStudio/en/ClassGroup_pseudo-property_of_TDataModule

The use of GroupDescendentsWith is to tell the IDE that a particular control is part of a specific to a particular framework. The documentation for StartClassGroup says:

The streaming system allows the classes that can be loaded and saved to be registered in separate groups. This allows the IDE to distinguish between cross-platform and Windows-only classes. StartClassGroup creates a new group of classes, and adds the class specified by AClass to that group.

The simplest way for you to deal with this is to change the ClassGroup pseudo-property on your data module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top