我可以使定制Delphi组件在uses子句中添加多个单元吗? [英] Can I make a custom Delphi component add multiple units to the uses clause?

查看:148
本文介绍了我可以使定制Delphi组件在uses子句中添加多个单元吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究XE2中的一些组件。是否可能有更多的组件的单位添加到其删除的形式的uses子句中?



示例:
当我从已经构建并安装的包中选择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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆