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

标签 delphi delphi-xe2 datamodule

在 Delphi 的早期版本中,我使用数据模块 (TDataModule) 作为保存非可视组件的位置,以避免主窗体困惑。在Delphi XE2中,当我创建一个新的数据模块时,它只允许我在其中放置与数据库相关的组件(例如TADOConnectionTDataSource)。这是为什么?我怎样才能在其中放入其他组件?有替代方案吗?

最佳答案

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

默认ClassGroup数据模块是System.Classes.TPercient。这指定数据模块是框架中立的,因此既不接受 VCL 组件也不接受 FMX 组件。

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

阅读 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 XE2 数据模块只需要数据库组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097246/

相关文章:

rest - Delpi XE8 REST 客户端和 HubSpot

delphi - TPipeServer 和 TPipeClient 组件的读/写示例代码和安全检查

delphi - Delphi XE2 中从右到左的组合框,带有样式

DELPHI:泛型和多态性

Delphi 单元自动添加到西雅图的使用中

delphi - 显示 TTreeViewItem 的 Expander 按钮

delphi - 在Delphi包中 "implicitly imported"总是坏事吗?

delphi - 在图像上绘制多边形

delphi - 当操作管理器位于数据模块中时,键盘快捷键未捕获?