Delphi XE2数据模块只需要数据库组件?

在以前的Delphi版本中,我已经使用数据模块(TDataModule)作为一个地方来保持非可视化组件,以避免混乱主窗体。在Delphi XE2中,当我创建一个新的数据模块时,它只允许我在数据库中放置数据库相关的组件(如TADOConnection和TDataSource)。为什么会这样,我该怎么把其他组件放在其中?有办法吗

解决方法

数据模块随XE2版本而改变。记住,XE2除了长期存在的VCL之外,还引入了一个新的组件框架FireMonkey。一个新的伪属性,名为 ClassGroup添加到数据模块。这将控制哪些组件可以添加到IDE设计器中的数据模块中。

数据模块的认值为ClassGroup为System.Classes.TPersistent。这指定数据模块是框架中性的,因此不接受VCL组件或FMX组件。

在您的情况下,您可能希望接受VCL组件,因此您需要指定Vcl.Controls.TControl的ClassGroup。

阅读documentation中有关ClassGroup的全部信息。

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

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...