[prev] [prev-tail] [tail] [up]

#### Variables

The following variables are defined and initialized in the system unit:

     var
       output,input,stderr : text;
       exitproc : pointer;
       exitcode : word;
       stackbottom : Cardinal;

The variables ExitProc, exitcode are used in the Free Pascal exit scheme. It works similarly to the one in Turbo Pascal:

When a program halts (be it through the call of the Halt function or Exit or through a run-time error), the exit mechanism checks the value of ExitProc. If this one is non-Nil, it is set to Nil, and the procedure is called. If the exit procedure exits, the value of ExitProc is checked again. If it is non-Nil then the above steps are repeated. So when an exit procedure must be installed, the old value of ExitProc should be saved (it may be non-Nil, since other units could have set it). In the exit procedure the value of ExitProc should be restored to the previous value, such that if it was non-Nil the exit-procedure can be called.

Listing: refex/ex98.pp

Program Example98;
{ Program to demonstrate the exitproc function. }
Var
OldExitProc : Pointer;
Procedure MyExit;
begin
Writeln('My Exitproc was called. Exitcode = ',ExitCode);
{ restore old exit procedure }
ExitProc:=OldExitProc;
end;
begin
OldExitProc:=ExitProc;
ExitProc:=@MyExit;
If ParamCount>0 Then
Halt(66);
end.

The ErrorAddr and ExitCode can be used to check for error-conditions. If ErrorAddr is non-Nil, a run-time error has occurred. If so, ExitCode contains the error code. If ErrorAddr is Nil, then ExitCode contains the argument to Halt or 0 if the program terminated normally.

ExitCode is always passed to the operating system as the exit-code of the current process.

Remark: The maximum error code under L I N U X and U N I X like operating systems is 127. Under GO32, the following constants are also defined :

     const
        seg0040 = $0040;
        segA000 = $A000;
        segB000 = $B000;
        segB800 = $B800;

These constants allow easy access to the bios/screen segment via mem/absolute.

The randomize function uses a seed stored in the RandSeed variable:

       RandSeed    : Cardinal;

This variable is initialized in the initialization code of the system unit.

Other variables indicate the state of the application.

       IsLibrary : boolean;
       IsMultiThread : boolean;

The IsLibrary variable is set to true if this module is a shared library instead of an application. The IsMultiThread variable is set to True if the application has spawned other threads, otherwise, and by default, it is set to False.

[prev] [prev-tail] [front] [up]