home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / LIMITKEY.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-03  |  1KB  |  44 lines

  1. Unit LimitKey;
  2.  
  3. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  4. { A unit to ensure that only a set of prescribed key presses will  }
  5. { be accepted by the program. The procedure LimitChar has three    }
  6. { parameters, one to declare the set of acceptable characters as a }
  7. { string, the second the variable name for the entered character   }
  8. { and the third a boolean value indicating whether the keypress    }
  9. { involved an Escape Sequence (27;nn) or an Extended Code (0;nn).  }
  10. { Based on a unit by David Arber of David Arber Associates.        }
  11. {                                                                  }
  12. { LIMITKEY.PAS  ->  .TPU      R Shaw            3.12.92            }
  13. {__________________________________________________________________}
  14.  
  15. Interface
  16.  
  17. Uses Crt;
  18.  
  19. Procedure LimitChar(s : string; var Key : char; var Ekey : boolean);
  20.  
  21. Implementation
  22.  
  23. Procedure LimitChar(s : string; var Key : char; var Ekey : boolean);
  24. begin
  25.   repeat
  26.     Ekey := False;
  27.     Key  := Readkey;
  28.     if Key = #0 then
  29.       begin
  30.         Ekey := True;
  31.         Key  := Readkey;
  32.         exit;
  33.       end;
  34.     if Key = #27 then
  35.       begin
  36.         Ekey := True;
  37.         Key  := Readkey;
  38.         exit;
  39.       end;
  40.   until pos(Key,s) > 0;
  41. end;
  42.  
  43. end.
  44.