在 Delphi 的早期版本中,我使用数据模块 (TDataModule
) 作为保存非可视组件的位置,以避免主窗体困惑。在Delphi XE2中,当我创建一个新的数据模块时,它只允许我在其中放置与数据库相关的组件(例如TADOConnection
和TDataSource
)。这是为什么?我怎样才能在其中放入其他组件?有替代方案吗?
最佳答案
数据模块随 XE2 版本而更改。请记住,除了长期存在的 VCL 之外,XE2 还引入了新的组件框架 FireMonkey。一个新的伪属性,名为 ClassGroup
已添加到数据模块。这控制可以将哪些组件添加到 IDE 设计器中的数据模块。
默认ClassGroup
数据模块是System.Classes.TPercient
。这指定数据模块是框架中立的,因此既不接受 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 XE2 数据模块只需要数据库组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097246/