Delphi XE2 Data Module expects only database components?

旧巷老猫 提交于 2019-11-29 05:36:26

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

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!