Delphi 7 has a main menu option for Component|Install Component that guides you through the process of getting a component onto the Palette. Unfortunately, that functionality was lost in the IDE’s transformation to the Borland Developer Studio. I won’t go into details but I was not happy to say the least when I learned of this change.
Regardless, your choices of installing components hasn’t changed it’s just you’re no longer guided through the process. I thought it might be useful to walk through a few scenarios using Delphi 2007. There are many ways to accomplish these tasks so don’t consider this your only option.
Creating and installing a new component into a new Package
Here are the steps necessary to create a new component and get it installed onto the palette though refer to the section below on the caveat with the New VCL Component wizard:
- Start the IDE
- Select File|New|Package
- Select File|Save As and give your package the desired name
- Select View|Project Manager
- Right click the package node and select Options then be sure to fill in the Description for this package as it will be used in the Install Packages dialog
- Select Component|New VCL Component… which will display the New VCL Component Wizard (see note below)
- Select TButton as the ancestor and click Next
- Leave the defaults for Classname etc. and click Next
- Select “Add unit to Package1.bdsproj project”
- Select View|Project Manager and right click Package1 and select Install
That will get you a new design time package with a new component installed and on your palette. If you have an existing .PAS file that contains a component(s) all you need to do is right click the Contains node under your package and select “Add…”.
Installing an existing component into a new package
The steps here are pretty much the same as above except at step 4 instead of starting the New VCL Component wizard simply open the .PAS file that contains the component(s) and add it to the Contains node of your package.
Installing components into an existing package
In this case, you’ve already created and installed a design time package and you’d like to add a new component.
- Select Component|Install Packages (Sure, this may seem a bit odd since the package we want is already installed)
- Find the desired package and select it in the Design Packages listbox
- Click the Edit button which will prompt you to cancel the dialog and open the package as a project
- Select View|Project Manager
- Expand the package node and right click the Contains node under the package and select “Add…” and add your existing .PAS file or select Component|New VCL Component and follow the steps above
- Right click the package node in the Project Manager and select Compile which will rebuild and reinstall your design time package
Installing existing design time packages
If you have existing component packages and you want to get them on the palette:
- Select Component|Install Packages
- Click the Add button and multi-select the design time packages you want to install then click Ok. You don’t really have to worry too much if the package you select is design time or runtime as the IDE will let you know if there is an issue installing the package.
The issue with the New VCL Component Wizard
There is one rather major flaw with the New VCL Component Wizard and that’s that it places both design-time and runtime code into a single unit. The runtime code is the code that implements the component itself. The design-time code is the Register procedure with the call to RegisterComponents which should be removed and placed in a different unit which belongs it a design time package. In the first scenario above it would be wise to create a second, design-time only package and split the code as described. Additionally, you should mark your packages explicitly as design-time and runtime using Usage Options from the Project Options dialog.
Mixing design-time and runtime code in a single package is a bad idea and needs to be avoided. Design-time code isn’t necessary at runtime and typically contains property and/or component editors along with various registration calls which are only meaningful when the package is installed in the IDE.
Let me know if this was helpful and if you’ve been impacted by the removal of Component|Install Component functionality. I’ve already discussed it with Nick Hodges.
[UPDATE: May 9, 2007] Also see Creating Packages from the Delphi wiki.