Sign in Join
Wiki copytemporary

IDE Window: Code Templates/fi: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11[[Lazarus IDE/fi|Luettelo kaikista kehitysympäristön ikkunoista]]
22
33## Mitä ovat koodilyhenteet?
44
55Koodilyhenteet 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.
66
77Tämä ikkuna sallii muokata nykyisiä koodilyhenteitä tai lisätä omia.
88
99The 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.
1010
1111## Example 1 - ifb
1212
1313type
1414
1515 ifb|
1616
1717The pipe should represent the cursor. Press Ctrl+j. It will be expanded to
1818
1919 if | then begin
2020
2121 end;
2222
2323Again the pipe represents the cursor. You can see the cursor has moved as well.
2424
2525This template is called 'ifb' and is defined as follows:
2626
2727 if | then begin
2828
2929 end;
3030
3131This time the pipe '\|' is a real character. It defines the cursor position after inserting the template.
3232
3333## Example 2 - Using macros
3434
3535This example shows how to create a code template 'w' which inserts a line with the current procedure name.
3636
3737- Click on the 'Add' button. A dialog pops up. Set Token to 'w' and Comment to 'writeln(ProcName)', then click Ok.
3838- Your new item has been added to the list box.
3939- In the source below fill in
4040
41-` writeln(' ',|);`
41+```text
42+ writeln(' ',|);
43+```
4244
4345- 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:
4446
45-` writeln('$ProcedureName() ',|);`
47+```text
48+ writeln('$ProcedureName() ',|);
49+```
4650
4751- Click 'Ok' to save and close the code template dialog.
4852- Move the cursor into a method body, type 'w':
4953
5054For instance:
5155
52-` procedure TForm1.FormDestroy(Sender: TObject);`\
53-` begin`\
54-`   w|`\
55-` end;`
56+``` pascal
57+ procedure TForm1.FormDestroy(Sender: TObject);
58+ begin
59+ w|
60+ end;
61+```
5662
5763The pipe should represent here the blinking cursor, not a character.
5864
5965- Press Ctrl+j. You will get:
6066
61-` procedure TForm1.FormDestroy(Sender: TObject);`\
62-` begin`\
63-`   writeln('TForm1.FormDestroy ',|);`\
64-` end;`
67+``` pascal
68+ procedure TForm1.FormDestroy(Sender: TObject);
69+ begin
70+ writeln('TForm1.FormDestroy ',|);
71+ end;
72+```
6573
6674---
6775*From the Free Pascal wiki, page "IDE Window: Code Templates/fi", as it stood on 2006-10-15 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history