AddExitProc/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # AddExitProc | |
| 2 | 2 | ||
| 3 | 3 | Mit **AddExitProc**, kann man eine Procedure zuweisen, welche bei Programm-Ende aufgerufen wird.\ | |
| 4 | 4 | Auch bei Beendigungen durch eine Laufzeitfehler.\ | |
| 5 | - | ||
| 5 | + | ||
| 6 | 6 | Gegenüber dem einfachen [[ExitProc/de|ExitProc]] hat diesen den Vorteil, das man sich nicht um das sichern und wieder aufrufen der alten [[ExitProc/de|ExitProc]] kümmern muss, dies geschieht mit **AddExitProc** automatisch im Hintergrund.\ | |
| 7 | 7 | ||
| 8 | 8 | ## Beispiel | |
| 9 | 9 | ||
| 10 | 10 | In diesem Beispiel, wird bewusst eine Datei geöffnet, welche es nicht gibt. | |
| 11 | 11 | ||
| 12 | 12 | ``` pascal | |
| 13 | 13 | program AddExitProc_Example; | |
| 14 | 14 | ||
| 15 | 15 | const | |
| 16 | 16 | MyExitCode = 123; | |
| 17 | 17 | ||
| 18 | 18 | procedure Ende; | |
| 19 | 19 | begin | |
| 20 | 20 | WriteLn('Das ist das Ende'); | |
| 21 | 21 | case ExitCode of | |
| 22 | 22 | 2: begin | |
| 23 | 23 | WriteLn('Datei nicht gefunden'); | |
| 24 | 24 | end; | |
| 25 | 25 | MyExitCode: begin | |
| 26 | 26 | WriteLn('Es wurde bewusst mit ', MyExitCode, ' abgebrochen'); | |
| 27 | 27 | end; | |
| 28 | 28 | else begin | |
| 29 | 29 | WriteLn('Fehler: ', ExitCode); | |
| 30 | 30 | end; | |
| 31 | 31 | end; | |
| 32 | 32 | end; | |
| 33 | 33 | ||
| 34 | 34 | var | |
| 35 | 35 | f: file; | |
| 36 | 36 | ||
| 37 | 37 | begin | |
| 38 | 38 | // Neue ExitProc zuweisen. | |
| 39 | 39 | AddExitProc(@Ende); | |
| 40 | 40 | ||
| 41 | 41 | // Eine Datei öffnen, welche es nicht gibt. | |
| 42 | 42 | Assign(f, 'abc.txt'); | |
| 43 | 43 | ||
| 44 | 44 | // Dies löst einen Laufzeitfehler 2 aus. | |
| 45 | 45 | Reset(f); | |
| 46 | 46 | ||
| 47 | 47 | // Mit eigenem Code abbrechen. | |
| 48 | 48 | Halt(MyExitCode); | |
| 49 | 49 | end. | |
| 50 | 50 | ``` | |
| 51 | 51 | ||
| 52 | 52 | ## Siehe auch | |
| 53 | 53 | ||
| 54 | 54 | - [[ExitProc/de|ExitProc und ExitCode]] - Programm-Ende abfangen und ExitCode auswerten. | |
| 55 | 55 | ||
| 56 | 56 | Autor: Mathias | |
| 57 | 57 | ||
| 58 | 58 | --- | |
| 59 | 59 | *From the Free Pascal wiki, page "AddExitProc/de", as it stood on 2020-05-19 after a change by FTurtle, 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).* |
