home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ABORTU.ZIP / TESTABRT.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-03-27  |  3.0 KB  |  78 lines

  1. program TestAbrt;
  2. {
  3. Small test program to illustrate use of AbortU unit.
  4.  
  5. Note that the message you want is visible even if you re-direct output.
  6.  
  7. To try out some of the various options, you will have to compile to disk
  8. and then execute from the command line to see the effects if standard output
  9. is re-directed.
  10.  
  11. Note that you need to change the constant GraphPath for your directory setup
  12. if you try the graphics mode.
  13.  
  14. Normally one would expect that a program written to use Graph would provide
  15. its own exit handler to make sure that under all termination conditions the
  16. CloseGraph procedure is executed (whether or not Abort was called).
  17.  
  18. ClosGrph is a tiny unit that does nothing except CloseGraph during the exit
  19. procedure processing provided by Turbo.  It could be used by you if you write
  20. a graphics program that does all of its work in the main program so that you
  21. never really need to write your own units.
  22. }
  23.  
  24. Uses
  25.    AbortU,
  26.    CRT,
  27.    Graph,
  28.    ClosGrph;
  29.  
  30. const
  31.    NUL = #$00;
  32.    GraphPath = 'C:\LANG\TURBO4'; {Change this to match your directory setup}
  33.  
  34. var
  35.    ch : char;
  36.    GraphDriver : integer;
  37.    GraphMode   : integer;
  38.    ErrorCode   : integer;
  39.  
  40. begin
  41.    writeln ('Enter your choice of N - to see an abort during normal operation');
  42.    writeln ('                     G - to see an abort during graphics mode');
  43.    writeln ('                     S - to see an abort during standard output');
  44.    writeln ('                         Also try this with standard output redirected');
  45.    repeat
  46.       ch := upcase(ReadKey);
  47.    until ch in ['N','G','S'];
  48.    case ch of
  49.       'N': begin
  50.               writeln ('This is normal output using CRT.');
  51.               write ('Press any key to abort now . . ');
  52.               ch := ReadKey; if ch=NUL then ch := ReadKey;
  53.               AbortMsg ('This was an abort after normal output using CRT');
  54.            end;
  55.       'G': begin
  56.               GraphDriver := Detect;
  57.               InitGraph (GraphDriver, GraphMode, GraphPath);
  58.               ErrorCode := GraphResult;
  59.               if ErrorCode <> grOK then
  60.                  AbortNumMsg (ErrorCode,'InitGraph reported this error code');
  61.               OutTextXY (0,0,'This is in graphics mode.  Press any key to abort now . . ');
  62.               ch := ReadKey; if ch=NUL then ch := ReadKey;
  63.               AbortMsg ('This was an abort from graphics mode');
  64.            end;
  65.       'S': begin
  66.               writeln;
  67.               writeln ('If you want to see this work when standard output is re-directed,');
  68.               writeln ('then run the program with TESTABRT >somefile');
  69.               writeln;
  70.               assign (output,''); {change next writes to (possibly re-directed)}
  71.               rewrite (output);   {standard output device}
  72.               writeln ('This is output to the standard output device');
  73.               write   ('Now the program will abort . .');
  74.               AbortMsg ('This is an abort message after standard output');
  75.            end;
  76.    end;
  77. end.
  78.