Default parameter/de: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # Default Parameter | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | In einer [[Procedure/de|procedure]] oder [[Function/de|function]], kann man auch Default Parameter deklarieren. Dabei muss beachtet werden, das die nur bei den letzten Paramter gestattet ist. | |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 5 | + | Die letzten 2 Parameter haben Defaultwerte, und somit ist die erlaubt. | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 7 | 8 | procedure Erlaubt(a: byte; b: byte = 4; c: byte = 5); | |
| 8 | 9 | ``` | |
| 9 | 10 | ||
| 10 | - | ||
| 11 | - | ||
| 11 | + | Nur der 2 Parameter hat eine Defaultwert und somit gibt dies einen Fehler. | |
| 12 | + | ||
| 13 | + | ``` pascal | |
| 12 | 14 | procedure Verboten(a: byte; b: byte = 4; c: byte); | |
| 13 | 15 | ``` | |
| 14 | 16 | ||
| 15 | - | ||
| 16 | - | ||
| 17 | 17 | ## Beispiel | |
| 18 | 18 | ||
| 19 | - | ||
| 20 | - | ||
| 19 | + | Diese Beispiel zeig eine Anwendung des Default Parameter. | |
| 20 | + | ||
| 21 | + | ``` pascal | |
| 21 | 22 | program Example; | |
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 23 | + | ||
| 24 | + | procedure Print(s: string; LineEnd: boolean = False); | |
| 25 | + | begin | |
| 26 | + | if LineEnd then begin | |
| 27 | + | WriteLn(s); | |
| 28 | + | end else begin | |
| 29 | + | Write(s); | |
| 30 | + | end; | |
| 31 | + | end; | |
| 32 | + | ||
| 33 | + | begin | |
| 34 | + | Print('Hello '); // Entspricht Print('Hello ', False); | |
| 35 | + | Print('World !', True); | |
| 36 | + | Print('======', False); | |
| 37 | + | Print('=======', True); | |
| 38 | + | end. | |
| 38 | 39 | ``` | |
| 39 | 40 | ||
| 40 | - | ||
| 41 | + | Autor: Mathias | |
| 41 | 42 | ||
| 42 | 43 | --- | |
| 43 | - | ||
| 44 | + | *From the Free Pascal wiki, page "Default parameter/de", as it stood on 2020-02-12 after a change by Trev, 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).* |
