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