home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tvinp102.zip / TVINP102.INT < prev    next >
Text File  |  1992-08-21  |  8KB  |  254 lines

  1. { $X+,R-,S-,N+,E+,D-,L-,O+,A+,G-,B-,V- }
  2. unit tvinp101;
  3.  
  4. interface
  5.  
  6. uses drivers,dialogs,msgbox,objects,views;
  7.  
  8. type
  9.  
  10. {--------------------------------------------------------------------------}
  11. { TinputAncestor is a base class for all of the other numeric input classes}
  12. { It is not intended to ever be instantiated                               }
  13. {--------------------------------------------------------------------------}
  14. PInputAncestor = ^TinputAncestor;
  15. TInputAncestor = object(TInputLine)
  16.   procedure SetState(AState : word; Enable : Boolean); virtual;
  17.   procedure BadNumber; virtual;
  18. end;
  19.  
  20. {--------------------------------------------------------------------------}
  21. { TInputNumerals is nothing more glorified than a TInputLine that only     }
  22. { accepts the numbers 0..9.  None of the numerical inputs are derived from }
  23. { it, but I have found it useful in the past                               }
  24. {--------------------------------------------------------------------------}
  25.  
  26. PInputNumerals = ^TInputNumerals;
  27. TInputNumerals = object(TInputAncestor)
  28.   procedure HandleEvent(var Event : TEvent); virtual;
  29. end;
  30.  
  31. Pinputnumber = ^Tinputnumber;
  32.  
  33. {------------------------------------------------------------------------}
  34. { Tinputnumber is also base class for all of the other numeric input     }
  35. { classes except TInputNumerals. It is not intended to ever be           }
  36. { instantiated either.                                                   }
  37. {------------------------------------------------------------------------}
  38. Tinputnumber = object(TInputAncestor)
  39. { Methods }
  40.  
  41. { For loading from streams }
  42.   constructor load(var s : TStream);
  43.  
  44. { For storing to streams }
  45.   procedure store(var s : TStream); virtual;
  46.  
  47. { Returns the byte count of the data stored.  Not the length of the
  48.   string used for editing, but the actual binary number }
  49.   function datasize : word; virtual;
  50.  
  51. { Overridden methods for data transfer with dialog boxes }
  52.   procedure getdata(var rec); virtual;
  53.   procedure setdata(var rec); virtual;
  54.  
  55. { Handler for keyboard events to strip unwanted characters and validate
  56.   input for numbers when the focus changes }
  57.   procedure handleevent(var event : Tevent); virtual;
  58.  
  59. { Numeric validation routine.  Checks that a number is within the programmer
  60.   selected boundaries }
  61.   function valid(command:word) : boolean; virtual;
  62.  
  63.   destructor done; virtual;
  64. private
  65. { These variables/methods are not available for direct manipulation }
  66.  
  67.   defaulted : boolean;
  68.   default_value : pointer;    { Default value
  69.                                 initialized during construction }
  70.   storagesize : word;         { This is the number returned by datasize() }
  71.   value,min,max : pointer;    { Actual value storage locations }
  72.   lngth,decs : byte;          { String formatting information for display }
  73.  
  74. { The TinputNumber constructor is private to guarantee that a instance
  75.   of TinputNumber is never formally created }
  76.   constructor init(var bounds : Trect; Amaxlen : byte;
  77.               var minimum,maximum,valu; mysize : word; length,decimals : byte);
  78.  
  79. end;
  80.  
  81. Pinputint = ^Tinputint;
  82.  
  83. { Integer dialog box input }
  84. Tinputint = object(Tinputnumber)
  85.  
  86. { Constructor to allow program control over allowed data values.  The first
  87.   two parameters are self explanatory if you're familiar with Turbo Vision }
  88.   constructor init(var bounds : Trect; Amaxlen : byte;
  89.               minimum,maximum,valu : integer);
  90.  
  91. { Creates a default integer, which allows inputs for all numbers between
  92.   -32768..32767 }
  93.   constructor default(var bounds : Trect; Amaxlen : byte);
  94.  
  95. { Handleevent strips off all non numeric input when a TinputInt is focused }
  96.   procedure handleevent(var event : Tevent); virtual;
  97.  
  98. { Valid checks that the integer entered is within the prescibed range }
  99.   function valid(command:word) : boolean; virtual;
  100. end;
  101.  
  102.  
  103. PInputLong = ^TInputlong;
  104. { Long integer input object.  Methods identical to TinputInt }
  105.  
  106. TInputlong = object(TInputnumber)
  107.   constructor init(var bounds : Trect; Amaxlen : byte;
  108.               minimum,maximum,valu : longint);
  109.   constructor default(var bounds : Trect; Amaxlen : byte);
  110.   procedure handleevent(var event : Tevent); virtual;
  111.   function valid(command:word) : boolean; virtual;
  112. end;
  113.  
  114.  
  115. PInputReal = ^TInputReal;
  116.  
  117. { Software real input object }
  118. TInputReal = object(TInputnumber)
  119.  
  120. { The TinputReal object adds the length and decimals parameters to
  121.   the constructor to allow string formatting.  Use these parameters
  122.   as you would in a call to writeln(x:length:decimals) }
  123.   constructor init(var bounds : Trect; Amaxlen : byte;
  124.               minimum,maximum,valu : real; length,decimals : byte);
  125.  
  126. { Provides a default real input that takes any value within the valid
  127.   range of real numbers as defined in the TP documentation }
  128.   constructor default(var bounds : Trect; Amaxlen : byte);
  129.  
  130. { Valid for TinputReal allows entry of exponents as well as numbers and
  131.   optional sign }
  132.   function valid(command:word) : boolean; virtual;
  133. end;
  134.  
  135. PInputSingle = ^TInputSingle;
  136. { Single type input object.  Refer to TinputReal }
  137.  
  138. TInputSingle = object(TInputnumber)
  139.   constructor init(var bounds : Trect; Amaxlen : byte;
  140.               minimum,maximum,valu : single; length,decimals : byte);
  141.   constructor default(var bounds : Trect; Amaxlen : byte);
  142.   function valid(command:word) : boolean; virtual;
  143. end;
  144.  
  145. PInputDouble = ^TInputDouble;
  146. { Double type input object.  Refer to TinputReal }
  147.  
  148. TInputDouble = object(TInputnumber)
  149.   constructor init(var bounds : Trect; Amaxlen : byte;
  150.               minimum,maximum,valu : double; length,decimals : byte);
  151.   constructor default(var bounds : Trect; Amaxlen : byte);
  152.   function valid(command:word) : boolean; virtual;
  153. end;
  154.  
  155. PInputExtended = ^TInputExtended;
  156. { Extended type input object.  Refer to TinputReal }
  157.  
  158. TInputExtended = object(TInputnumber)
  159.   constructor init(var bounds : Trect; Amaxlen : byte;
  160.               minimum,maximum,valu : extended; length,decimals : byte);
  161.   constructor default(var bounds : Trect; Amaxlen : byte);
  162.   function valid(command:word) : boolean; virtual;
  163. end;
  164.  
  165. PInputComp = ^TInputComp;
  166. { Comp type input object }
  167. TInputComp = object(TInputnumber)
  168.  
  169. { The TinputComp constructor adds a length parameter, but no decimals
  170.   parameter since comp types are whole numbers }
  171.   constructor init(var bounds : Trect; Amaxlen : byte;
  172.               minimum,maximum,valu : comp; length,decimals: byte);
  173.   constructor default(var bounds : Trect; Amaxlen : byte);
  174.   function valid(command:word) : boolean; virtual;
  175. end;
  176.  
  177. { These are the stream registration records for use with the above
  178.   objects.  You must register each individual object with Turbo Vision
  179.   before any reading or writing to/from streams can take place.
  180.   A procedure called RegisterNumerics is provided to register all of
  181.   the provided objects }
  182.  
  183. const
  184.  
  185. Immediate_Checking : Boolean = True;
  186.  
  187. Rinputint : Tstreamrec = (
  188.   objtype : 700;
  189.   vmtlink : ofs(typeof(Tinputint)^);
  190.   load : @Tinputint.load;
  191.   store : @Tinputint.store
  192. );
  193.  
  194. Rinputlong : Tstreamrec = (
  195.   objtype : 701;
  196.   vmtlink : ofs(typeof(Tinputlong)^);
  197.   load : @Tinputlong.load;
  198.   store : @Tinputlong.store
  199. );
  200.  
  201. Rinputreal : Tstreamrec = (
  202.   objtype : 702;
  203.   vmtlink : ofs(typeof(Tinputreal)^);
  204.   load : @Tinputreal.load;
  205.   store : @Tinputreal.store
  206. );
  207.  
  208. Rinputsingle : Tstreamrec = (
  209.   objtype : 703;
  210.   vmtlink : ofs(typeof(Tinputsingle)^);
  211.   load : @Tinputsingle.load;
  212.   store : @Tinputsingle.store
  213. );
  214.  
  215. Rinputdouble : Tstreamrec = (
  216.   objtype : 704;
  217.   vmtlink : ofs(typeof(Tinputdouble)^);
  218.   load : @Tinputdouble.load;
  219.   store : @Tinputdouble.store
  220. );
  221.  
  222. Rinputextended : Tstreamrec = (
  223.   objtype : 705;
  224.   vmtlink : ofs(typeof(Tinputextended)^);
  225.   load : @Tinputextended.load;
  226.   store : @Tinputextended.store
  227. );
  228.  
  229. Rinputcomp : Tstreamrec = (
  230.   objtype : 706;
  231.   vmtlink : ofs(typeof(Tinputcomp)^);
  232.   load : @Tinputcomp.load;
  233.   store : @Tinputcomp.store
  234. );
  235.  
  236. Rinputnumerals : Tstreamrec = (
  237.   objtype : 707;
  238.   vmtlink : ofs(typeof(Tinputnumerals)^);
  239.   load : @Tinputnumerals.load;
  240.   store : @Tinputnumerals.store
  241. );
  242.  
  243. { Procedure to call RegisterType() for all of the provided input types }
  244. procedure RegisterNumerics;
  245.  
  246. implementation
  247.  
  248. begin
  249.   new(limits[1]);
  250.   new(limits[2]);
  251. end.
  252.  
  253.  
  254.