New/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | Zurück zu den [[Reserved words/de|reservierten Wörtern]]. | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | Das reservierte Wort new gehört zur objektorientierten Programmierung. | |
| 4 | 4 | ||
| 5 | - | ||
| 5 | + | Das reservierte Wort new erstellt eine neue Instanz. | |
| 6 | 6 | ||
| 7 | 7 | Beispiel 1: | |
| 8 | 8 | ||
| 9 | 9 | ``` pascal | |
| 10 | 10 | var | |
| 11 | 11 | intI: ^Integer; | |
| 12 | 12 | ||
| 13 | 13 | begin | |
| 14 | 14 | ... | |
| 15 | 15 | if assigned(intI) then ... // Prüft, ob intI eine Adresse zugewiesen wurde | |
| 16 | 16 | ... | |
| 17 | 17 | new(intI); // Weist intI eine gültige Adresse zu | |
| 18 | 18 | ... | |
| 19 | 19 | dispose(intI); // Gibt die Adresse wieder frei | |
| 20 | 20 | ... | |
| 21 | 21 | ``` | |
| 22 | 22 | ||
| 23 | 23 | Beispiel 2: | |
| 24 | 24 | ||
| 25 | 25 | ``` pascal | |
| 26 | 26 | type | |
| 27 | 27 | PListItem = ^TListItem; | |
| 28 | 28 | TListItem = record | |
| 29 | 29 | data: string; | |
| 30 | 30 | next: PListItem; // Verweis auf das nächste Element | |
| 31 | 31 | end; | |
| 32 | 32 | ||
| 33 | 33 | var | |
| 34 | 34 | Liste: PListItem; | |
| 35 | 35 | ||
| 36 | 36 | begin | |
| 37 | 37 | ... | |
| 38 | 38 | New(Liste^.next); // Fügt der Liste ein neues Element hinzu | |
| 39 | 39 | Liste^.next^.data := ''; // Leert das Element | |
| 40 | 40 | Liste^.next^.next := nil; // setzt den nachfolgenden Zeiger zur Sicherheit auf nichts | |
| 41 | 41 | ... | |
| 42 | 42 | dispose(Liste); // Gibt die Liste wieder frei | |
| 43 | 43 | ... | |
| 44 | 44 | ``` | |
| 45 | 45 | ||
| 46 | 46 | --- | |
| 47 | 47 | *From the Free Pascal wiki, page "New/de", as it stood on 2020-02-21 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).* |
