Plug-ins Explained - Linking your package
(Page 3 of 4 )
After you've created your package, the next step is to link it to your main application. You can link your run-time packages in two ways, statically or dynamically. When using static linking, you simply add the names of the Pascal files to the "uses" clause of your application. Don't worry about the same units being listed in your package. By adding these units you ensure that the VCL is used when you eventually run the application. When you run your application with statically linked packages, it ensures that the run-time packages are present.
If the run-time packages are not present, an error will be generated and program execution will be stopped. Now, keep in mind that our overall aim is to use packages as an plug-in, so this situation will not do. Static linking also won't work for use because you will need to re-link the package to the application when you change the package's contents or replace it with another package. This pretty much takes away the independence of the core application when used with packages. This basically means that every time you change something in the package, you will need to recompile the core application to which it needs to be linked. It is for this reason that static linking is not suitable for our purposes at all. So let's take a look at dynamic linking.
If you've ever used DLL files in your applications, you should not have any problems working with dynamic packages, because they work pretty much in the same way. Dynamic packages are basically a "special" type of DLL that works only with Delphi applications. So, why are dynamic packages suitable to use for creating plug-ins?
- You can update the package without crashing the core application.
- All the relevant VCL functionality is stored in the package, which allows for a smaller executable.
- You load the package when the main application starts without crashing it, because you can add code to check whether or not the package is available.
- You can load and unload the package(s) as and when you need them as opposed to a statically linked package that has to be linked no matter what.
It is the flexibility to load and unload a package that is of particular interest to us, because that is how we are going to manage our plug-ins.
Next: An example >>
More Delphi-Kylix Articles
More By Leidago