Friday, September 12, 2003

In the past, there has been some misunderstandings about what Delphi Packages are and how they are used and/or managed. I recently posted this to an unnamed newsgroup that seemed generally useful. It has been edited for content so that any unreleased information has been removed... however the gist of it is still there.

Since we are working on the next releast of Delphi that will target the Microsoft .NET platform, assemblies are going to continue this level of confusion in spades. Sometimes folks have trouble visualizing how packages (and assemblies) inter-relate. hopefully this will shed a little light on how the dependencies work. This is valid for both Delphi/Win32/Linux and Delphi for .NET. Hopefully this will answer the common question of "why can't I just link with this one package and have the rest of the units linked into my app?"

Think of an assembly or package as a tree branch (this analogy will break down at a certain point but the visual is still valid). Now that branch has other branches attached to it as well. You can take any of the "sub-branches" and break them off and they still form a complete independent branch. However the original branch is no longer complete. Now if you sort-of reverse how you view the dependencies... there is always a "root" package. This "root" package will contain the Delphi System unit. Since package rules say that a certain unit can only exist in one and only one package, all other packages above the root must link with that same root package. Just like a tree can't have a branch that doesn't eventually flow back to the root. Now at any point above this "root" you can move units between packages almost at will, but if you view each package above the "root" as being its own "root" then the rules simply repeat. This is all the same with assemblies, however there is a bit of an anomaly with mscorlib and System.Xml.. they reference each-other. The "root" in .NET is mscorlib. In a sense with .NET your apps will always link with at least one "package" or "assembly."

So when you pick a package or assembly with which to link your application, you will implicitly link with all the packages with which that package links all the way down to the Delphi System unit (or in .NET, down to mscorlib). By carefully choosing a point in this dependency tree, you can control what units will be linked into your application and which ones will remain in packages.