home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tvinp101.zip / TVINP101.INT < prev    next >
Text File  |  1992-05-13  |  7KB  |  225 lines

  1. {$X+,R-,S-,N+,E+,D-,L-,O+,F+,A+,G-,B-,V-}
  2. UNIT tvinp101;
  3.  
  4. INTERFACE
  5.  
  6. USES drivers, dialogs, msgbox, objects, views;
  7.  
  8. TYPE
  9.  
  10. pinputnumber = ^tinputnumber;
  11.  
  12. {------------------------------------------------------------------------}
  13. { Tinputnumber is a base class for all of the other numeric input classes}
  14. { It is not intended to ever be instantiated                             }
  15. {------------------------------------------------------------------------}
  16. tinputnumber = OBJECT (tinputline)
  17. { Methods }
  18.  
  19. { For loading from streams }
  20.   CONSTRUCTOR load (VAR s : tstream);
  21.  
  22. { For storing to streams }
  23.   PROCEDURE store (VAR s : tstream); VIRTUAL;
  24.  
  25. { Returns the byte count of the data stored.  Not the length of the
  26.   string used for editing, but the actual binary number }
  27.   FUNCTION datasize : WORD; VIRTUAL;
  28.  
  29. { Overridden methods for data transfer with dialog boxes }
  30.   PROCEDURE getdata (VAR rec); VIRTUAL;
  31.   PROCEDURE setdata (VAR rec); VIRTUAL;
  32.  
  33. { Handler for keyboard events to strip unwanted characters and validate
  34.   input for numbers when the focus changes }
  35.   PROCEDURE handleevent (VAR event : tevent); VIRTUAL;
  36.  
  37. { Numeric validation routine.  Checks that a number is within the programmer
  38.   selected boundaries }
  39.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  40.  
  41.   DESTRUCTOR done; VIRTUAL;
  42. private
  43. { These variables/methods are not available for direct manipulation }
  44.  
  45.   defaulted : BOOLEAN;        { Flag to indicate which constructor was called }
  46.   storagesize : WORD;         { This is the number returned by datasize() }
  47.   value, min, max : POINTER;    { Actual value storage locations }
  48.   lngth, decs : BYTE;          { String formatting information for display }
  49.  
  50. { The TinputNumber constructor is private to guarantee that a instance
  51.   of TinputNumber is never formally created }
  52.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  53.               VAR minimum, maximum, valu; mysize : WORD; LENGTH, decimals : BYTE);
  54.  
  55. END;
  56.  
  57. pinputint = ^tinputint;
  58.  
  59. { Integer dialog box input }
  60. tinputint = OBJECT (tinputnumber)
  61.  
  62. { Constructor to allow program control over allowed data values.  The first
  63.   two parameters are self explanatory if you're familiar with Turbo Vision.
  64.   Minimum and maximum are the min/max values that the input line will
  65.   accept.  Valu is the initial value the input will take. }
  66.  
  67.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  68.               minimum, maximum, valu : INTEGER);
  69.  
  70. { Creates a default integer, which allows inputs for all numbers between
  71.   -32768..32767 }
  72.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  73.  
  74. { Handleevent strips off all non numeric input when a TinputInt is focused }
  75.   PROCEDURE handleevent (VAR event : tevent); VIRTUAL;
  76.  
  77. { Valid checks that the integer entered is within the prescibed range }
  78.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  79. END;
  80.  
  81.  
  82. pinputlong = ^tinputlong;
  83. { Long integer input object.  Methods identical to TinputInt }
  84.  
  85. tinputlong = OBJECT (tinputnumber)
  86.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  87.               minimum, maximum, valu : LONGINT);
  88.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  89.   PROCEDURE handleevent (VAR event : tevent); VIRTUAL;
  90.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  91. END;
  92.  
  93.  
  94. pinputreal = ^tinputreal;
  95.  
  96. { Software real input object }
  97. tinputreal = OBJECT (tinputnumber)
  98.  
  99. { The TinputReal object adds the length and decimals parameters to
  100.   the constructor to allow string formatting.  Use these parameters
  101.   as you would in a call to writeln(x:length:decimals) }
  102.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  103.               minimum, maximum, valu : REAL; LENGTH, decimals : BYTE);
  104.  
  105. { Provides a default real input that takes any value within the valid
  106.   range of real numbers as defined in the TP documentation }
  107.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  108.  
  109. { Valid for TinputReal allows entry of exponents as well as numbers and
  110.   optional sign }
  111.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  112. END;
  113.  
  114. pinputsingle = ^tinputsingle;
  115. { Single type input object.  Refer to TinputReal }
  116.  
  117. tinputsingle = OBJECT (tinputnumber)
  118.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  119.               minimum, maximum, valu : SINGLE; LENGTH, decimals : BYTE);
  120.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  121.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  122. END;
  123.  
  124. pinputdouble = ^tinputdouble;
  125. { Double type input object.  Refer to TinputReal }
  126.  
  127. tinputdouble = OBJECT (tinputnumber)
  128.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  129.               minimum, maximum, valu : DOUBLE; LENGTH, decimals : BYTE);
  130.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  131.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  132. END;
  133.  
  134. pinputextended = ^tinputextended;
  135. { Extended type input object.  Refer to TinputReal }
  136.  
  137. tinputextended = OBJECT (tinputnumber)
  138.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  139.               minimum, maximum, valu : EXTENDED; LENGTH, decimals : BYTE);
  140.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  141.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  142. END;
  143.  
  144. pinputcomp = ^tinputcomp;
  145. { Comp type input object }
  146. tinputcomp = OBJECT (tinputnumber)
  147.  
  148. { The TinputComp constructor adds a length parameter, but no decimals
  149.   parameter since comp types are whole numbers }
  150.   CONSTRUCTOR init (VAR bounds : trect; amaxlen : BYTE;
  151.               minimum, maximum, valu : COMP; LENGTH, decimals : BYTE);
  152.   CONSTRUCTOR default (VAR bounds : trect; amaxlen : BYTE);
  153.   FUNCTION valid (command : WORD) : BOOLEAN; VIRTUAL;
  154. END;
  155.  
  156. { These are the stream registration records for use with the above
  157.   objects.  You must register each individual object with Turbo Vision
  158.   before any reading or writing to/from streams can take place.
  159.   A procedure called RegisterNumerics is provided to register all of
  160.   the provided objects }
  161.  
  162. CONST
  163. rinputint : tstreamrec = (
  164.   objtype : 700;
  165.   vmtlink : OFS (typeof (tinputint) ^);
  166.   load : @tinputint.load;
  167.   store : @tinputint.store
  168. );
  169.  
  170. rinputlong : tstreamrec = (
  171.   objtype : 701;
  172.   vmtlink : OFS (typeof (tinputlong) ^);
  173.   load : @tinputlong.load;
  174.   store : @tinputlong.store
  175. );
  176.  
  177. rinputreal : tstreamrec = (
  178.   objtype : 702;
  179.   vmtlink : OFS (typeof (tinputreal) ^);
  180.   load : @tinputreal.load;
  181.   store : @tinputreal.store
  182. );
  183.  
  184. rinputsingle : tstreamrec = (
  185.   objtype : 703;
  186.   vmtlink : OFS (typeof (tinputsingle) ^);
  187.   load : @tinputsingle.load;
  188.   store : @tinputsingle.store
  189. );
  190.  
  191. rinputdouble : tstreamrec = (
  192.   objtype : 704;
  193.   vmtlink : OFS (typeof (tinputdouble) ^);
  194.   load : @tinputdouble.load;
  195.   store : @tinputdouble.store
  196. );
  197.  
  198. rinputextended : tstreamrec = (
  199.   objtype : 705;
  200.   vmtlink : OFS (typeof (tinputextended) ^);
  201.   load : @tinputextended.load;
  202.   store : @tinputextended.store
  203. );
  204.  
  205. rinputcomp : tstreamrec = (
  206.   objtype : 706;
  207.   vmtlink : OFS (typeof (tinputcomp) ^);
  208.   load : @tinputcomp.load;
  209.   store : @tinputcomp.store
  210. );
  211.  
  212. { Procedure to call RegisterType() for all of the provided input types }
  213. PROCEDURE registernumerics;
  214.  
  215. IMPLEMENTATION
  216.  
  217.  { Object methods and support routines }
  218. BEGIN
  219.  { Note the automatic initialize of these two type pstring variables }
  220.   NEW (limits [1]^);
  221.   NEW (limits [2]^);
  222. END.
  223.  
  224.  
  225.