Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
Dynamic World of Packages
Part 1: Static linking or dynamic loading?
 More of this Feature
• Part 2: Creating Dynamic Forms
• Part 3: Dynamic Form in Dynamic Package
• Download CODE
 Join the Discussion
"Post your views, or look for guidance on the questions and issues that matter to Dynamic Package loading issues in Delphi"
Discuss!
  Related Resources
• BPL vs. DLL
• DLL's and Delphi
• try/finally error handling
 Elsewhere on the Web
Using Packages in Delphi
• Dynamic packages in Delphi
• Advanced Dynamic Packages
• Building addin packages
• Inside the BPL - dynamic components
 

See how to store a Delphi form inside a BPL. Find out about dynamically embedding forms into an application - building applications your users can modify at runtime.

As stated in the BPL vs. DLL article, Packages (Borland Package Libraries) are a very powerful feature of Delphi. A package is a special dynamic-link library used by Delphi applications, the Delphi IDE, or both. Packages can contain units with code, components and forms, but also Delphi classes - this enables us to write object oriented code.

Usually, we use static linking when using routines in a Package. Packages listed in the Runtime Packages edit box of the Project | Options dialog window are automatically linked to our application when we compile. This is the most easiest way to use a runtime Package. With statically linked packages we write our code in the application exactly as if the packaged code (units, forms, etc) are a part of the application. We simply list the units contained in the package in the uses clause.

Dynamic at run-time...
Ordinarily, packages are linked statically when an applications starts. But we can use the LoadPackage and UnloadPackage RTL routines to load and unload packages dynamically at run-time. After the Package is loaded, the application calls the GetProcAddress API function to get the addresses of the exported BPL functions. The application calls the exported functions using the function pointers returned by GetProcAddress. To see how this mechanism really works just keep on reading...

Of course, it's not important whether we use statically linked or dynamically loaded packages, we must compile our application using run-time packages. Packages listed under Runtime Packages edit box will be linked statically, any other Packages our application need can be loaded dynamically. You should not add the packages we want to load dynamically in the applications Runtime Packages edit box, only the standard VCL packages it needs should be in the list.

Dynamic benefits
To note a few:
. When the Package is not available, an application using static linking simply terminates, while the run-time dynamic linking is able to respond to the error.
. If you're trying to provide plug-ins for your application dynamically loaded Packages are better. Suppose you have more that 50 forms in an application and depending on your user's program configuration only several are really used. It's better to store those forms inside a Package and dynamically load the needed instead of statically linking all 50 of them.
. Another advantage is that your application will load more quickly when using dynamic loading because not all the code needed to run the program is loaded when the application initially loads.

Next page > Creating a dynamic Form for a dynamic Package > Page 1, 2, 3

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.