This article on delphi.about.com gives a quick description on how to create component templates but doesn't really tell why it helps you.
Component templates are a way to quickly create a modified version of a standard component without writing any code. Let's assume you write lots of dialogs which contain an OK and a Cancel button (and who doesn't?). Now, doing it the classic way, you would have to do the following for each of these dialogs:
- Add a TButton from the component palette to your form
- Change its caption to "OK"
- Change its name to "b_OK" (or whatever your usual name for the OK button is)
- Change its Default property to true
Now, if you had a component template for an OK button, you could reduce this list to only step 1.
To create a component template for an OK button
- Follow the steps above to create the OK button on a form
- In the "Component" menu select "Create Component Template"
- Give it the name TOkButton (or whatever you prefer)
- Enter the name of the palette page on which you want your template to appear (default: Templates)
- Press OK
Now, remove your button from the form, switch to the palette page you just specified and, voila there is a TOkButton component. If you drop that component on your form, you will find, that it adds a preconfigured OK-Button.
The same goes for the Cancel button:
- Add a TButton from the component palette to your form
- Change its caption to "Cancel"
- Change its name to "b_Cancel"
- Change its Cancel property to true
Now, just create a similar TCancelButton component template and with dropping two components on a form you get a dialog with a default OK button and a Cancel button that is pressed using the Esc key.
But we can do even better:
What about adding both buttons at once? This is also possible because a component template also allows multiple components in a single template:
- Drop a TOkButton and a TCancelButton on your form
- Arrange them to your liking
- Select both and create a new component template TOkCancelButtons for them
Now you can add an OK and a Cancel button with just dropping one TOkCancelButton on your form.
Is this cool or what?
Of course you are not limited to buttons. You could for example create a labeled edit (but later Delphi versions already provide a TLabeledEdit component) or a labeled memo, e.g. TResultMemo for displaying the output of your program.