IDE Window: Code Templates/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: IDE Window: Code Templates/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | [[Lazarus IDE/fi|Luettelo kaikista kehitysympäristön ikkunoista]] | |
| 2 | + | ||
| 3 | + | ## Mitä ovat koodilyhenteet? | |
| 4 | + | ||
| 5 | + | 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. | |
| 6 | + | ||
| 7 | + | Tämä ikkuna sallii muokata nykyisiä koodilyhenteitä tai lisätä omia. | |
| 8 | + | ||
| 9 | + | 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. | |
| 10 | + | ||
| 11 | + | ## Example 1 - ifb | |
| 12 | + | ||
| 13 | + | type | |
| 14 | + | ||
| 15 | + | ifb| | |
| 16 | + | ||
| 17 | + | The pipe should represent the cursor. Press Ctrl+j. It will be expanded to | |
| 18 | + | ||
| 19 | + | if | then begin | |
| 20 | + | ||
| 21 | + | end; | |
| 22 | + | ||
| 23 | + | Again the pipe represents the cursor. You can see the cursor has moved as well. | |
| 24 | + | ||
| 25 | + | This template is called 'ifb' and is defined as follows: | |
| 26 | + | ||
| 27 | + | if | then begin | |
| 28 | + | ||
| 29 | + | end; | |
| 30 | + | ||
| 31 | + | This time the pipe '\|' is a real character. It defines the cursor position after inserting the template. | |
| 32 | + | ||
| 33 | + | ## Example 2 - Using macros | |
| 34 | + | ||
| 35 | + | This example shows how to create a code template 'w' which inserts a line with the current procedure name. | |
| 36 | + | ||
| 37 | + | - Click on the 'Add' button. A dialog pops up. Set Token to 'w' and Comment to 'writeln(ProcName)', then click Ok. | |
| 38 | + | - Your new item has been added to the list box. | |
| 39 | + | - In the source below fill in | |
| 40 | + | ||
| 41 | + | ` writeln(' ',|);` | |
| 42 | + | ||
| 43 | + | - 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: | |
| 44 | + | ||
| 45 | + | ` writeln('$ProcedureName() ',|);` | |
| 46 | + | ||
| 47 | + | - Click 'Ok' to save and close the code template dialog. | |
| 48 | + | - Move the cursor into a method body, type 'w': | |
| 49 | + | ||
| 50 | + | For instance: | |
| 51 | + | ||
| 52 | + | ` procedure TForm1.FormDestroy(Sender: TObject);`\ | |
| 53 | + | ` begin`\ | |
| 54 | + | ` w|`\ | |
| 55 | + | ` end;` | |
| 56 | + | ||
| 57 | + | The pipe should represent here the blinking cursor, not a character. | |
| 58 | + | ||
| 59 | + | - Press Ctrl+j. You will get: | |
| 60 | + | ||
| 61 | + | ` procedure TForm1.FormDestroy(Sender: TObject);`\ | |
| 62 | + | ` begin`\ | |
| 63 | + | ` writeln('TForm1.FormDestroy ',|);`\ | |
| 64 | + | ` end;` | |
| 65 | + | ||
| 66 | + | --- | |
| 67 | + | *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).* |
