Creating an About Box Plug-in - Creating a package
(Page 3 of 4 )
Now we need to create a package, so select File|New|Other and select the package icon. The package editor should appear. Add a form to the package. Then at the bottom of the unit, but before the "end," add the following:
initialization
RegisterClass(TForm2);
finalization
UnregisterClass(TForm2);
This will register the Tform class. We do this because we are going to use a new function called "GetClass()" that requires the class to be registered, so that it can find the class when it is called. Form and component classes are automatically registered when the form is loaded. In our case the form is not loaded, so we need to register them in the package, as each unit is initialized when the package is loaded and finalized when the package is unloaded.
Save the package as MyPlugin1, and then select the options button. You should now see a dialog with some tabs at the top. First, select the "Directories and Conditionals" tab and make sure that the output directory and DCP output directories point to the same directory as your project folder. Then go to the "Descriptions" tab and select "run-time only" in the usage options section. Click OK and you should now be back to the package editor. The form that you added to the package will be used as the "aboutbox" dialog, so try to make it look like one.
Once you've decorated the form, you can now compile the package. Check that the .bpl file is located in your project folder, as this is now your plug-in. We now need to dynamically link the plug-in to the main application, so close the package editor completely and open up your host application.
Remember that we are now dealing with a form and not just a routine as with our previous example. So we are going to use different methods to access the routines and forms contained in our plug-in. Our plug-in will expose a class, more specifically, the TForm2 class. So we use the "getclass()" function to retrieve it and then we will need to instantiate that class. This will enable us to call its methods, in other words we will be able to use all the usual methods that are available to a form. The getclass() function returns a registered persistent class, given its name, and has the following syntax:
function GetClass(const ClassName: string): TPersistentClass;
That's all we need to do to call the about form that is stored in the plug-in.
Next: Adding some more code >>
More Delphi-Kylix Articles
More By Leidago