Package contains a component that doesn't belong to it.
I'm creating some components and after installing and check which components have been registered there are some extra ones which aren't part of the package I've created. They are part of other packages we use in the system. Since the software 开发者_开发知识库uses both packages this raises errors about the same component being registered twice.
What's causing a component not listed in the contains
section to be registered in the package?
Delphi 2007
What's causing a component not listed in the contains section to be registered in the package?
Existence of the Register
procedure which calls RegisterComponents.
Two possibilities:
Your package is using a unit which registers its components by the standard
Register
procedure. This unit is not part of any other package, so it gets registered together with your package. In this case, you should get a warning about the implicitly used unit.Your package directly or indirectly depends on the package which contains the components. This package has not been installed yet, so it gets installed together with your package. When a package is loaded in the IDE, all units are enumerated recursively and every found
Register
procedure is called by the IDE. By installing a package you are effectively also installing all design packages it depends on.
If your package depends on components that are already included in another package, that package must be listed in the requires list of your package, so it uses the components from that other package. If the other package is not listed, the units your code uses will be included in your package. Now you have the same unit in two packages.
So find out in which package components or units your code depends on are included, and add that package to the requires section of your package. That way they won't be included in your package, but used from that other package.
Example: your unit is unit A. It uses unit B. Unit A is in your contains list, but unit B isn't. Package P already contains unit B. If you don't put package P in your requires list, unit B will also be included in your package, even if it is not in the contains list, since your package (your unit A) needs that unit to function. If you include package P in your requires list ("references" branch in project manager), unit B in package P will be used, and there is no duplication.
精彩评论