The Unofficial Newsletter of Delphi Users - by Robert Vivrette




Dynamically Loading Packages

by Alexander Mehlhorn - ahm@global.co.za

Its been a while since last I wrote an article, yet even then it was in German rather than in English.

The issue I want to talk about today is Packages. Now we are all not new to Delphi Packages. Yet has anyone ever tried to create his own for his own Application ? Why would I do that, if I could, you ask; well you might find the following reasons appealing:

On a Network with many Users you don't have to log anyone out when redistributing a part of your application if it is in Package format.

I have created a template for my Package Forms which you can install into Delphi and reuse afterwards by pressing New on Delphi's File Menu. I wanted my Forms to appear inside a Panel on the Mainform of my Application (similar to Outlook). Therefore I created a new type of Form that does not contain huge pointers all around and is actually (even thought it looks different in design) not a Form but a Scrollbox. You might know that a scrollbox is the face of the form which is the reason I used it.

Now when I create a new Package and add one of those types of forms into it then I can compile the package (without installing it into Delphi... that presents other problems...) Now I have created a component that is a TPanel but it acts as the Owner of any Package Form once the Package gets loaded. I drop this one onto the Mainform. Then I have a unit that will be compiled with the Package as well as the Application. This unit is responsible for automatically adding the Form within the Package onto the Panel when the Package gets loaded.

And if you have a look at my example it does exactly that. Now you can actually go around and play with packages that get loaded dynamically into your Application.

One additional thought. You have to set compile using packages to on. Even if it will not actually link into your packages the application needs to be able to support their loading.

Where I work we have used it quite extensively. Our Main Application never really changes anymore. Our Database Interface component resides there and the actual look and feel of the App. In the packages we have our forms that load and dispose themself upon a change in the Menu Navigation. Everything is fast and reliable and things never really go wrong. I am not 100% finished with this Idea but I need input from people who are interested in using it. It works fine but the talking between Application and Package is not always that easy. I do have workarounds for them but to explain them all would simply take to long if you have not seen it in action.

Try it out for yourself and send me an email if you have a wider interest than that. An example is on my homepage on the download area at http://www.global.co.za/~ahm. Its called the AHM Package Solution and comes complete with source and example. You can also download the example I have discussed in this article by clicking here.

Also if you do any changes please forward them to me and I will see what I can do to post it to everyone around. If you want to get updates about this just let me know and I will keep you posted on their progress.

Thanks!