Code templates are a way to insert large pieces of code at once. Each code templates is identified by a unique name. This name can be used to insert the associated piece of code in the text.
For example, the name ifthen could be associated to the following piece of code:
If | Then begin end
A code template can be inserted by typing its name, and pressing Ctrl-J when the cursor is positioned right after the template name.
If there is no template name before the cursor, a dialog will pop up to allow selection of a template.
If a vertical bar (—) is present in the code template, the cursor is positioned on it, and the vertical bar is deleted. In the above example, the cursor would be positioned between the if and then, ready to type an expression.
Code templates can be added and edited in the code templates dialog, reachable via the menu option ”Options—Environment—CodeTemplates”. The code templates dialog is shown in figure (6.6).
The top listbox in the code templates dialog shows the names of all known templates. The bottom half of the dialog shows the text associated with the currently highlighted code template. The following buttons are available:
Ok
Saves all changes and closes the dialog.
Edit
Pops up a dialog that allows the editing of the currently highlighted code template. Both the name and text can be edited.
New
Pops up a dialog that allows the entry of a new code template which will be added to the list. A name must be entered for the new template.
Delete
Deletes the currently highlighted code template from the list.
Cancel
Discards all changes and closes the dialog.
All templates are saved and are available the next time the IDE is started.
Remark Duplicates are not allowed. If an attempt is made to add a duplicate name to the list, an error will occur.