Shallow Waters

Wednesday, August 09, 2006

Quick post about Delphi packages

Over recent months (notably this afternoon) I've been regularly banging my head against a brick wall trying to wrap it around Delphi packages, design-time packages and installing packages. Finally, I believe that I have got this clear in my head.

What does it mean to install a package?

When you install a package, Delphi keeps a reference to the .bpl of the package in its settings (I presume that this means in the registry but I don't actually know where). When the package is installed and everytime Delphi launches subsequently it calls all Register procedures.

Typically the package is used as a placeholder for one or more components, in which case the Register procedure will simply add the components to the IDE.

Design-time packages can also peform other actions through the OTA API - basically allowing installation of the package to manipulate the IDE.

So there you have it - an installed package simply is a package that has it's Registry procedures invoked whenever Delphi starts.

What does it mean when a package 'requires' another package

As far as I can see, .pas file on the library path is available to any other unit. Additionally any unit which is wrapped up inside a Delphi Compiled Package (DCP) file is also available to any other unit. However linking implicitly into another package is considered bad form so Delphi warns you when it detects this. You can get rid of the warning if you add an explicit 'requires' from the client package to the used package.

Confused Yet? Let me tell you a story

The main area where I have become confused is when you have multiple copies of the DCP and BPL files available on the library path. By default, the Delphi library path has entries for $(DELPHI)\bin, $(DELPHI)\lib & $(DELPHI)\Projects\Bpl and will not warn you if these directories contain different version of the same files.

The first problem that I had installed a package with multiple versions on the library path. The actual installed package was in $(DELPHI)\Projects\Bpl but there was an out of date version in $(DELPHI)\lib (someone, who was probably me, must have changed this without thinking at some stage). This appeared to be causing Delphi some confusion as the new feature I had added to my component was not visible in the IDE but the new methods and properties could be accessed programatically.

Dutifully I closed down Delphi, deleted the offending BPL & DCP files and tried again. Still the same problem. I recompiled and reinstalled the the package. Still the same problem!

After rebooting, reinstalling and retesting about 50 times I finally spotted the problem.

We had split up our component library into a large run-time only package that housed all the actual components and a small design-time package that actually did the registering. I had been rebuiding the component package, rebuilding the design-time package and the reinstalling. The one thing I hadn't noticed was that the underlying component package also had an out of date duplicate in the $(DELPHI)\lib folder. This was being ignored by the editor and compiler because the top directory in the library path was referring to a folder containing all the latest DCUs but it was not being ignored when the package was installed.

You have been warned - don't do stupid things and you'll be fine!

0 Comments:

Post a Comment

<< Home