Creating Component Templates in Delphi

One nice feature of the Delphi IDE that I keep forgetting are Component Templates. That means you drop and customize one or multiple components on a form and then give them a new name so you can easily create them again on a different form in a different program.

Let’s start with a simple template for an OK button:

  1. Drop a button on a form.
  2. Give it a meaningful name, e.g. “btnOK
  3. Set its “Caption” property to “OK”.
  4. Set its “Default” property to True.
  5. Make sure that the button is sill selected.
  6. Select Component -> Create Component Template from the menu.
  7. Give it a name, e.g. “OKButton”.

That’s it. A new entry has been added to the Tool Palette. Now, whenever you want to add an OK button, you simply press Ctrl+Alt+P to bring up the Tool Plaette, then enter “OK” and maybe some more keys to filter the list and select the new entry. A copy of the created template will be added to your form. No need to change its properties again.

Now, a form usually has not just an OK but also a Cancel button, why not create a template “OkCancelButtons” for that?


(Click on the picture for an animated tutorial for the below.)

  1. Drop a button on a form.
  2. Give it a meaningful name, e.g. “btnOK
  3. Set its “Caption” property to “OK”.
  4. Set its “Default” property to True.
  5. Drop another button on the form.
  6. Move it to your liking in relation to the OK button.
  7. Set its “Caption” property to “Cancel”.
  8. Give it a meaningful name, e.g. “btnCancel”
  9. Set its “Cancel” property to True.
  10. Select both buttons with Shift+Left Mouse Button.
  11. Select Component -> Create Component Template from the menu.
  12. Give it a name, e.g. “OKCancelButton”.

Again, a new entry has been added to the Tool Palette which you can use whenever you need these two buttons on any form in any program. They will have the correct captions, the Default and Cancel properties will be set and they will be in the right place in relation to each other.

To get rid of a component template you don’t need any more, use the “Delete <component name>” entry context menu on the entry in the Tool Palette.

Component templates are stored in the file
%AppData%\Roaming\Embarcadero\BDS\{version}\bds.dct for current versions, and in delphi.dct in the executable directory for Delphi 6 and 7. I don’t know whether even older versions supported them, but if yes I’d expect them to store them in the same way as Delphi 6 and 7.

(Thanks to Ondrej Kelle for that link.)