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