Default parameter/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Default parameter/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # Default Parameter | |
| 2 | + | ||
| 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 | + | ||
| 5 | + | Die letzten 2 Parameter haben Defaultwerte, und somit ist die erlaubt. | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | procedure Erlaubt(a: byte; b: byte = 4; c: byte = 5); | |
| 9 | + | ``` | |
| 10 | + | ||
| 11 | + | Nur der 2 Parameter hat eine Defaultwert und somit gibt dies einen Fehler. | |
| 12 | + | ||
| 13 | + | ``` pascal | |
| 14 | + | procedure Verboten(a: byte; b: byte = 4; c: byte); | |
| 15 | + | ``` | |
| 16 | + | ||
| 17 | + | ## Beispiel | |
| 18 | + | ||
| 19 | + | Diese Beispiel zeig eine Anwendung des Default Parameter. | |
| 20 | + | ||
| 21 | + | ``` pascal | |
| 22 | + | program Example; | |
| 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. | |
| 39 | + | ``` | |
| 40 | + | ||
| 41 | + | Autor: Mathias | |
| 42 | + | ||
| 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).* |
