Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

delphi - Why is my Component auto adding other units to the uses interface?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...