IDE Window: Code Templates/fi

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr)

Luettelo kaikista kehitysympäristön ikkunoista

Mitä ovat koodilyhenteet?

Koodilyhenteet ovat lyhenteitä varsinaisesta koodista. Esimerkiksi: voit kirjoittaa 'cl' lähdekoodieditorissa ja painaa Ctrl+j näppäimiä yhtäaikaa jolloin kutsutaan 'cl' vastaavaa koodilyhennettä. Tämä ominaisuus säästää paljolta kirjoittamisen vaivalta.


Tämä ikkuna sallii muokata nykyisiä koodilyhenteitä tai lisätä omia.


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.

  • Click on the 'Add' button. A dialog pops up. Set Token to 'w' and Comment to 'writeln(ProcName)', then click Ok.
  • Your new item has been added to the list box.
  • In the source below fill in
 writeln(' ',|);
  • The pipe is really a pipe and defines the new cursor position. Now place the cursor after the first ' and click on the 'Insert macro' button. A dialog pops up showing all available code macros. Choose 'ProcedureName' and click 'Insert Macro'. You should now have:
 writeln('$ProcedureName() ',|);
  • Click 'Ok' to save and close the code template dialog.
  • Move the cursor into a method body, type 'w':

For instance:

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

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

  • Press Ctrl+j. You will get:
 procedure TForm1.FormDestroy(Sender: TObject);
 begin
   writeln('TForm1.FormDestroy ',|);
 end;