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

前端之家收集整理的这篇文章主要介绍了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.)
原文链接:https://www.f2er.com/delphi/103428.html

猜你在找的Delphi相关文章