我可以使定制Delphi组件在uses子句中添加多个单元吗? [英] Can I make a custom Delphi component add multiple units to the uses clause?
问题描述
示例:
当我从已经构建并安装的包中选择TCustomComponent时,将单元CustomComponent添加到窗体的uses子句中。我还想添加单位GlobalConstants。
有人知道这是否可以完成?
为您的组件创建一个设计时包(如果您还没有),并创建一个实现 ISelectionEditor
界面(最简单的方法是从 TSelectionEditor
类),并覆盖其虚拟 RequiresUnits()
方法列出您想在中显示的任何其他单位,使用组件的
子句。然后通过调用 Register()函数注册该类rel =noreferrer> RegisterSelectionEditor()
。
Indy 10 完全按照 TIdTCPServer
, TIdCmdTCPClient
和 TIdUDPServer
组件,以确保 IdContext
和 IdSocketHandle
units添加到使用
子句。看看 IdCoreSelectionEditors.pas
和 IdRegisterCore.pas
单位,看看Indy如何使用这个。
I'm working on some components in XE2. Is it possible to have more than the component's unit added to the uses clause of the form it's dropped on?
Example: When I choose the TCustomComponent from a package I've built and installed the unit CustomComponent is added to the form's uses clause. I would like to also add the unit GlobalConstants.
Does anyone know if this can be done?
Create a design-time package for your component (if you do not already have one) and create a class in it that implements the ISelectionEditor
interface (the easiest way is to derive from the TSelectionEditor
class) and overrides its virtual RequiresUnits()
method to list any additional units you want to appear in the uses
clause for your component. Then have your component's Register()
function register that class by calling RegisterSelectionEditor()
.
Indy 10 does exactly this for its TIdTCPServer
, TIdCmdTCPClient
, and TIdUDPServer
components to make sure the IdContext
and IdSocketHandle
units get added to uses
clauses. Look at the IdCoreSelectionEditors.pas
and IdRegisterCore.pas
units to see how Indy uses this.
这篇关于我可以使定制Delphi组件在uses子句中添加多个单元吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!