将组件添加到表单时,如何自动添加Delphi单位? [英] How are Delphi units automatically added when a component is added to a form?

查看:90
本文介绍了将组件添加到表单时,如何自动添加Delphi单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从IDE向表单添加 TXMLDocument ,则单元 Xml.XMLDoc,Xml.xmldom,Xml.XMLIntf,Xml。 Win.msxmldom 将自动添加(保存/编译时),IDE如何知道要添加这些单元。我知道为什么/如何添加 XMLDoc (它包含 TXMLDocument ),但是其他呢?

If I add a TXMLDocument to a form from the IDE, the units Xml.XMLDoc, Xml.xmldom, Xml.XMLIntf, Xml.Win.msxmldom are automatically added (on save/compile), how does the IDE know to add these units. I understand why/how XMLDoc is added (it contains TXMLDocument) but what about the others.

另外,如果我将DOMVendor从MSXML更改为ADOM XML v4,则会自动添加 Xml.adomxmldom (在下一次编译时)。此时,我可以删除 Xml.Win.msxmldom ,而无需将其自动添加回去。 IDE如何基于组件属性知道这一点?

Additionally if I change the DOMVendor from MSXML to ADOM XML v4, Xml.adomxmldom is automatically added (on the next compile). At this point I can remove Xml.Win.msxmldom without it being added back automatically. How does the IDE know this based on a component property?

我有两个原因要问这个问题,首先是好奇心,但是其次我要清理大量的单位(数百个)。该项目使用DevExpress,并向使用中添加了其他文件堆-例如,添加 TcxSpinEdit ,然后添加 cxSpinEdit,cxGraphics,cxControls,cxLookAndFeels,cxLookAndFeelPainters ,cxContainer,cxEdit,cxTextEdit,cxMaskEdit 添加。我想最小化从窗体中删除控件(但它们的单元仍保留在使用中)的uses子句,因此需要了解更好地添加控件的过程。

I have two reasons for asking this question, firstly curiosity, but secondly I'm cleaning up the uses section of a large number of units (hundreds). The project uses DevExpress, and it adds heaps of additional files to the uses - for instance add a TcxSpinEdit then cxSpinEdit, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, cxTextEdit, cxMaskEdit are added. I'm wanting to minimize the uses clause where controls have been removed from forms (but their units remain in the uses) and thus need to understand the process whereby they are added better.

推荐答案

组件可以安排其在设计器中的存在,将特定的单元强制添加到该单元的use子句中。他们通过调用 RegisterSelectionEditor 来注册其 TSelectionEditor 子类。这些子类覆盖 TSelectionEditor.RequiresUnits ,并在其中指定必须添加的单位。

Components can arrange that their presence in the designer forces specific units to be added to the unit's uses clause. They do so by calling RegisterSelectionEditor to register their TSelectionEditor sub-classes. These sub-classes override TSelectionEditor.RequiresUnits and there specify the units which must be added.

例如:

uses
  DesignEditors;
....
type
  TMySelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

procedure TMySelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  Proc('MyUnit');
end;

procedure Register;
begin
  RegisterSelectionEditor(TMyComponent, TMySelectionEditor);
end;

这篇关于将组件添加到表单时,如何自动添加Delphi单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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