AddExitProc
Deutsch · English
AddExitProc
With AddExitProc, you can assign a procedure that is called when the program ends; even when terminated by a runtime error.
Compared to the simple ExitProc, this has the advantage that you don't have to worry about saving and calling up the old ExitProc, this happens automatically in the background with AddExitProc.
In this example, a file that does not exist is deliberately opened:
program AddExitProc_Example;
const
MyExitCode = 123;
procedure end;
begin
WriteLn('This is the end');
case ExitCode of
2:
begin
WriteLn('file not found');
end;
MyExitCode:
begin
WriteLn('It was deliberately terminated with ', MyExitCode);
end;
else
begin
WriteLn('Error: ', ExitCode);
end;
end;
end;
var
f : file;
begin
// Assign new ExitProc
AddExitProc(@end);
// Open a file that doesn't exist
Assign(f, 'abc.txt');
// This triggers runtime error 2
Reset(f);
// Cancel with your own code.
Halt(MyExitCode);
end.See also
From the Free Pascal wiki, page "AddExitProc", 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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
