9

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.

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?

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Alister
  • 6,527
  • 4
  • 46
  • 70
  • IDE also populates uses clause before saving module. – Free Consulting Dec 17 '13 at 21:23
  • 1
    This is a little off-topic but CNPack offers a good Uses clause cleaner ... – Hugh Jones Dec 17 '13 at 21:33
  • @HughJones Yup, it is what I'm using, although it fails to correctly clean uses in many of my units (removes/leaves extra characters), but works well for detection. Also Icarus, which amongst other things indicates when you can move a unit from the interface to implementation. – Alister Dec 18 '13 at 01:54
  • 1
    Please pay attention to the tags you're adding to your question. "units-of-measurement" is not anything near a Delphi "unit". – Ken White Dec 18 '13 at 04:01
  • @Alister - what version of Delphi ? I ask because I have been using it on Delphi 5 projects. I though that was why the odd error was ocurring with CNPack. – Hugh Jones Dec 18 '13 at 08:49

1 Answers1

14

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.

For instance:

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;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490