Category : Pascal Source Code
Archive   : ABORTU.ZIP

Output of file : TESTABRT.PAS contained in archive : ABORTU.ZIP

program TestAbrt;
Small test program to illustrate use of AbortU unit.

Note that the message you want is visible even if you re-direct output.

To try out some of the various options, you will have to compile to disk
and then execute from the command line to see the effects if standard output
is re-directed.

Note that you need to change the constant GraphPath for your directory setup
if you try the graphics mode.

Normally one would expect that a program written to use Graph would provide
its own exit handler to make sure that under all termination conditions the
CloseGraph procedure is executed (whether or not Abort was called).

ClosGrph is a tiny unit that does nothing except CloseGraph during the exit
procedure processing provided by Turbo. It could be used by you if you write
a graphics program that does all of its work in the main program so that you
never really need to write your own units.


NUL = #$00;
GraphPath = 'C:\LANG\TURBO4'; {Change this to match your directory setup}

ch : char;
GraphDriver : integer;
GraphMode : integer;
ErrorCode : integer;

writeln ('Enter your choice of N - to see an abort during normal operation');
writeln (' G - to see an abort during graphics mode');
writeln (' S - to see an abort during standard output');
writeln (' Also try this with standard output redirected');
ch := upcase(ReadKey);
until ch in ['N','G','S'];
case ch of
'N': begin
writeln ('This is normal output using CRT.');
write ('Press any key to abort now . . ');
ch := ReadKey; if ch=NUL then ch := ReadKey;
AbortMsg ('This was an abort after normal output using CRT');
'G': begin
GraphDriver := Detect;
InitGraph (GraphDriver, GraphMode, GraphPath);
ErrorCode := GraphResult;
if ErrorCode <> grOK then
AbortNumMsg (ErrorCode,'InitGraph reported this error code');
OutTextXY (0,0,'This is in graphics mode. Press any key to abort now . . ');
ch := ReadKey; if ch=NUL then ch := ReadKey;
AbortMsg ('This was an abort from graphics mode');
'S': begin
writeln ('If you want to see this work when standard output is re-directed,');
writeln ('then run the program with TESTABRT >somefile');
assign (output,''); {change next writes to (possibly re-directed)}
rewrite (output); {standard output device}
writeln ('This is output to the standard output device');
write ('Now the program will abort . .');
AbortMsg ('This is an abort message after standard output');