home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_TRC.ZIP / NESTTRC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-05-12  |  1.5 KB  |  49 lines

  1. {════════════════════════════ NESTTRC.PAS ════════════════════════════}
  2. { This program demonstrates the use of a local Trace Procedure.       }
  3. {═════════════════════════════════════════════════════════════════════}
  4. Program NestTrc;
  5.  
  6. Uses TRACE;
  7.  
  8. PROCEDURE Global;
  9.  VAR LocalVar: Byte;
  10.  
  11.  FUNCTION NestedFunction: Byte;
  12.  BEGIN
  13.    NestedFunction := 215;
  14.  END; {FUNCTION NestedFunction}
  15.  
  16.  PROCEDURE IncrementLocalVar;
  17.  Var n:Byte;
  18.  BEGIN
  19.    FOR n := 1 TO 255 DO BEGIN
  20.     Inc(LocalVar);
  21.     Inline($90);
  22.    END;
  23.  END; {PROCEDURE IncrementLocalVar;}
  24.  
  25. {═══════════════════════════ CheckLocalVar ═══════════════════════════}
  26. { This is the Pascal Trace Procedure.  Note that the Trace Procedure  }
  27. { can be a nested Procedure, which can inspect/write/modify/etc any   }
  28. { global or local variables which are known within the current scope, }
  29. { and can similarly call any global or local procedures or functions  }
  30. { which are known within the current scope.  Nested Trace procedures  }
  31. { must be local to the CURRENT block.                                 }
  32. {═══════════════════════════ CheckLocalVar ═══════════════════════════}
  33.  PROCEDURE CheckLocalVar;
  34.  BEGIN
  35.    IF LocalVar = NestedFunction THEN TRelease;
  36.    TReturn;   {- Return from Trace interrupt -}
  37.  END; {PROCEDURE CheckLocalVar}
  38.  
  39. BEGIN {PROCEDURE Global}
  40.  LocalVar := 0;
  41.  TraceOn(@CheckLocalVar);
  42.  IncrementLocalVar;
  43.  TraceOff;    {- Deactivate trace by the end of the current block -}
  44. END; {PROCEDURE Global}
  45.  
  46. BEGIN {MAIN}
  47.   Global;
  48. END.
  49.