3

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)??

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144

1 Answers1

3

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • That's the part of the documentation that I have referenced and understood. The other half, the GroupDescendentsWith stuff, not. I only could find a limited description in the Delphi help. And that does not answer my final question either. – Jan Doggen Apr 25 '14 at 06:17
  • Why are you not prepared to use `ClassGroup` as intended? – David Heffernan Apr 25 '14 at 06:20
  • I have removed the ClassGroup alltogether, because we do only Win32. That 'solves' it for now. But I have still written the question because I want to understand what's going on. – Jan Doggen Apr 25 '14 at 06:22
  • I don't really understand what you don't understand. Also, FMX runs on Win32. What you mean is that you only do VCL. In which was you should set the class group to VCL. – David Heffernan Apr 25 '14 at 06:24
  • Your 10-4 arithmetic seems flawed. You need to show registration for all 10 so that we can check your counting. Who says that the other 3 components are registered in a similar way. – David Heffernan Apr 25 '14 at 06:26
  • Oops, cut that out. Updating. – Jan Doggen Apr 25 '14 at 06:45
  • Look at the inheritance for the other controls. You'll find that all the removed controls are framework specific. – David Heffernan Apr 25 '14 at 07:00
  • I don't know this framework but I bet that lots of the components derive from `TSDDataSet`. That should explain the arithmetic. – David Heffernan Apr 25 '14 at 07:20
  • Must be something like that. TSDSession, TSDDatabase, TSDScript, TSDMonitor, TSDSQLBaseServer, TSDUpdateSQL derive (directly or indirectly) from TComponent; TSDQuery, TSDMacroQuery, TSDStoredProc, TSDTable from TSDDataSet, so the count still does not match, but I'm not going to spend more time on it. – Jan Doggen May 01 '14 at 11:14