为什么我的组件会自动将其他单元添加到用户界面? [英] Why is my Component auto adding other units to the uses interface?

查看:108
本文介绍了为什么我的组件会自动将其他单元添加到用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一些我自己的自定义组件,有些只是派生自其他组件,如TCustomButton,TCustomListBox等。



让我说,我有 TMyButton = class(TCustomButton)并且这是一个名为MyButton的单元,我已经将该组件注册到打包并安装到IDE中。



现在我将创建一个新的空项目并将一个TMyButton放到窗体中。当我编译项目时,它会自动将界面部分添加到这些单元中:

  ..,StdCtrls,MyButton; 

我期待MyButton当然要添加,但希望StdCtrls不是。



这不是很糟糕,但是我的其他组件的一些更糟糕的是,例如来自 TCustomActionMainMenuBar ,当我添加在我的表单和编译我得到这些额外的单位添加:

  ..,ToolWin,ActnMan,ActnCtrls,ActnMenus,MyMenu; 

我想创建自己的组件的一个原因是防止添加了很多单位名称接口部分,我想做自己的绘画和更改默认属性等。



当我将3或4个组件添加到表单,自动添加了一个额外的6-10个单位名称,我不希望这种情况发生。



所以我的问题是可以防止IDE自动添加单元在接口部分的名称?



事实上,我已经拥有我自己的组件源的实际使用界面中的不需要的单元名称,我以为会是足够的。我的组件知道他们需要哪些单元,那么为什么窗体的源文件需要知道/被允许包含这些名称呢?



我只想要$ code> MyButton,MyMenu; 自动添加,而不是所有添加的其他常用单元名称。

解决方案

有可能您的组件是从已注册 TSelectionEditor 的其他组件派生的实现(请参阅 RegisterSelectionEditor())覆盖虚拟 TSelectionEditor.RequiresUnits()方法将所需单元插入到中使用子句。这样做的一个原因是如果这些组件定义依赖于其他单位类型的属性/事件。


I have been writing some of my own custom components, some are simply derived from other components such as TCustomButton, TCustomListBox etc.

Lets say then I have TMyButton = class(TCustomButton) and this is in a unit named MyButton, I have registered this component in a packaged and installed into the IDE.

Now I will create a new empty Project and drop a TMyButton to the form. When I compile the project it automatically adds to the interface section these units:

.., StdCtrls, MyButton;

I was expecting MyButton of course to be added, but had hoped StdCtrls was not.

That is not so bad, but some of my other components are worse, one for example is derived from TCustomActionMainMenuBar and when I add that to my form and compile I get these extra units added:

.., ToolWin, ActnMan, ActnCtrls, ActnMenus, MyMenu;

One of the reasons I wanted to create my own components was to prevent so many unit names been added to the interface section, that and I wanted to do my own painting and change default properties etc to them.

By the time I add 3 or 4 of my components to the form, an extra 6-10 unit names are been added automatically and I dont want this to happen.

So my question - is it possible to prevent the IDE from automatically adding unit names to the interface section?

The fact that I already have the "unwanted" unit names in the actual uses interface of my own components source I thought would have been sufficient. My components know which units they need, so why must the source File of a form need to know / be allowed to included the names too?

I just want MyButton, MyMenu; automatically added, not all the other common unit names to be added with them.

解决方案

Chances are that your components are deriving from other components that have registered TSelectionEditor-derived implementations (see RegisterSelectionEditor()) that override the virtual TSelectionEditor.RequiresUnits() method to insert required units into uses clauses. One reason to do this is if those components define properties/events that rely on types in those other units.

这篇关于为什么我的组件会自动将其他单元添加到用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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