AddExitProc/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: AddExitProc/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # AddExitProc | |
| 2 | + | ||
| 3 | + | Mit **AddExitProc**, kann man eine Procedure zuweisen, welche bei Programm-Ende aufgerufen wird.\ | |
| 4 | + | Auch bei Beendigungen durch eine Laufzeitfehler.\ | |
| 5 | + | \ | |
| 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 | + | ||
| 8 | + | ## Beispiel | |
| 9 | + | ||
| 10 | + | In diesem Beispiel, wird bewusst eine Datei geöffnet, welche es nicht gibt. | |
| 11 | + | ||
| 12 | + | ``` pascal | |
| 13 | + | program AddExitProc_Example; | |
| 14 | + | ||
| 15 | + | const | |
| 16 | + | MyExitCode = 123; | |
| 17 | + | ||
| 18 | + | procedure Ende; | |
| 19 | + | begin | |
| 20 | + | WriteLn('Das ist das Ende'); | |
| 21 | + | case ExitCode of | |
| 22 | + | 2: begin | |
| 23 | + | WriteLn('Datei nicht gefunden'); | |
| 24 | + | end; | |
| 25 | + | MyExitCode: begin | |
| 26 | + | WriteLn('Es wurde bewusst mit ', MyExitCode, ' abgebrochen'); | |
| 27 | + | end; | |
| 28 | + | else begin | |
| 29 | + | WriteLn('Fehler: ', ExitCode); | |
| 30 | + | end; | |
| 31 | + | end; | |
| 32 | + | end; | |
| 33 | + | ||
| 34 | + | var | |
| 35 | + | f: file; | |
| 36 | + | ||
| 37 | + | begin | |
| 38 | + | // Neue ExitProc zuweisen. | |
| 39 | + | AddExitProc(@Ende); | |
| 40 | + | ||
| 41 | + | // Eine Datei öffnen, welche es nicht gibt. | |
| 42 | + | Assign(f, 'abc.txt'); | |
| 43 | + | ||
| 44 | + | // Dies löst einen Laufzeitfehler 2 aus. | |
| 45 | + | Reset(f); | |
| 46 | + | ||
| 47 | + | // Mit eigenem Code abbrechen. | |
| 48 | + | Halt(MyExitCode); | |
| 49 | + | end. | |
| 50 | + | ``` | |
| 51 | + | ||
| 52 | + | ## Siehe auch | |
| 53 | + | ||
| 54 | + | - [[ExitProc/de|ExitProc und ExitCode]] - Programm-Ende abfangen und ExitCode auswerten. | |
| 55 | + | ||
| 56 | + | Autor: Mathias | |
| 57 | + | ||
| 58 | + | --- | |
| 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).* |
