In the previous article we saw how to call a routine from a package as well as how to dynamically load a package into the main application. In this second part of a two-part article explaining plug-ins, we are going to look at how to create a real world plug-in.
Our plug-in will involve creating an about box for our host application. It is a fairly simple example, but is useful for those of you who would want to show the current version of your application or whatever else you think would work with it. Before we build this example, let's summarize what we've covered so far.
So far we've covered the creation and use of packages, as well as their components. Then we discussed how to use the routines stored in a package from the main application.
We have not talked about the differences between packages and DLL files, so let's do a quick comparison. This might help you when deciding which method to use when creating a plug-in.
Packages are specific to Delphi i.e they only work with applications that are written in Delphi.
Packages enable you to store Delphi classes, forms and more importantly, components.
Because of dynamic linking, packages can save you memory, because only one copy of the VCL is loaded into memory. This makes it available to all Delphi applications that use run-time packages. Imagine that every single Delphi application on your computer had to load VCL in memory -- it would take a lot of memory!
Packages are version specific, i.e you cannot use a package that you created in Delphi 6 with an application that you built with Delphi 7.
DLLs enable you to store procedures and functions, as well as entire Delphi forms, but they cannot store Delphi components.
DLLs can be used by any application whether they are written in Delphi or not, unlike packages which are specific to Delphi applications.
When updating a DLL, you simply change your routines (or whatever), recompile the DLL and ship it off; all the applications that were using this DLL will still be able to use it. You cannot do this with packages without changing the executable, as they are version specific. So if you want to ship a new version of a package, you will have to change the executable using it as well. It would be an absolute pain if your package is used by several applications!
So now you have a better idea of how the two methods compare. The next step is for you to experiment with the two technologies to make your applications truly extensible.