IDE Window: Code Templates/es

This is an old revision of IDE Window: Code Templates/es, edited by Iskraelectrica at . The current revision is 53488.

New page: {{IDE Window: Code Templates}} == What are Code Templates? == Code Templates are texts with an abbreviation. For example: You can type 'cl' in the source editor and then type Ctrl+J to i...

What are Code Templates?

Code Templates are texts with an abbreviation. For example: You can type 'cl' in the source editor and then type Ctrl+J to invoke the code templates starting with 'cl'. This feature is a great time saver.

This dialog allows you to edit the existing or add your own templates.

The texts can contain macros. And you can add your own macros by creating a design time package and using the macrointf.pas of the IDEIntf package.

Example 1 - ifb

type

  ifb|

The pipe should represent the cursor. Press Ctrl+j. It will be expanded to

  if | then begin

  end;

Again the pipe represents the cursor. You can see the cursor has moved as well.

This template is called 'ifb' and is defined as follows:

if | then begin

end; 

This time the pipe '|' is a real character. It defines the cursor position after inserting the template.

Example 2 - Using macros

This example shows how to create a code template 'w' which inserts a line with the current procedure name.

 writeln(' ',|);
 writeln('$ProcedureName() ',|);

For instance:

 procedure TForm1.FormDestroy(Sender: TObject);
 begin
   w|
 end;

The pipe should represent here the blinking cursor, not a character.

 procedure TForm1.FormDestroy(Sender: TObject);
 begin
   writeln('TForm1.FormDestroy ',|);
 end;