home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / BTV200.ZIP / BTVTYPE.INT < prev    next >
Text File  |  1993-12-18  |  6KB  |  198 lines

  1. {*
  2. *=========================================================================
  3. *  BTVTYPE.PAS  Version 2.0
  4. *
  5. *  BTRIEVE data type conversion routines for Turbo Pascal 6.0.
  6. *
  7. *  Copyright (c) 1993 by Richard W. Hansen, all rights reserved.
  8. *
  9. *
  10. *  Requires Turbo Pascal version 6.0
  11. *
  12. *
  13. *  Registration and payment of a license fee is required for any use, whether
  14. *  in whole or part, of this source code.
  15. *=========================================================================
  16. *
  17. *}
  18.  
  19. {****************************************************************************}
  20. {*   REVISION HISTORY                                                       *}
  21. {*                                                                          *}
  22. {*  Date     Who  What                                                      *}
  23. {* ======================================================================== *}
  24. {* 06/05/92  RWH  First version.                                            *}
  25. {* 09/07/93  RWH  Month and Day were backwards in BDateRec                  *}
  26. {****************************************************************************}
  27.  
  28. UNIT BTVType;
  29. {$F-}
  30. {$X+}
  31. {$A-}
  32. {$V-}
  33. {$N+,E+}
  34.  
  35.  
  36. INTERFACE
  37.  
  38.  
  39. TYPE
  40.   BDateRec  = record
  41.     Day   : Byte;
  42.     Month : Byte;
  43.     Year  : Word;
  44.   end;
  45.  
  46.  
  47.   BTimeRec  = record
  48.     Hundred : Byte;
  49.     Second  : Byte;
  50.     Minute  : Byte;
  51.     Hour    : Byte;
  52.   end;
  53.  
  54.  
  55. {
  56.   This Unit includes routines to convert Btrieve data types to and from
  57.   Pascal strings. Also included are routines for converting the BFloat types
  58.   to Turbo Pascal Singles, and Doubles.
  59.  
  60.   These routines are intended to ease the use of the Btrieve data types.
  61.   At first, some of them may seem redundant or of little use. They are
  62.   designed primarily for use with raw data from Btrieve records. All the
  63.   routines use untyped VAR parameters to handle the Btrieve types that are
  64.   not defined in Pascal. Untyped VAR parameters get around Pascal's strict
  65.   type checking, so you should exercise a bit more care calling these
  66.   routines.
  67.  
  68.   A typical call to convert IEEE single to a string might be:
  69.  
  70.     St := FloatToStr(Buffer[10], 4, 10, 4);
  71.  
  72.   Notice how the untyped parameter lets you convert data from any part of a
  73.   record buffer (though you could just as well have passed a variable of
  74.   type single in this example). Most of the routines have a size parameter,
  75.   in the example above it is the second parameter (4). The 4 indicates that
  76.   we want to convert a 4 byte Single into a string.
  77.  
  78.   It is very important that you pass the correct size. The size always refers
  79.   to the size of the Btrieve type and controls the type conversion (say to
  80.   single or double) or the size of resulting data when converting from a
  81.   string to a Btrieve type. If you specify the size incorrectly, you will
  82.   get garbage results or overwrite other data in memory.
  83.  
  84.   There are a couple of conversion routines left out, string to time and
  85.   string to date, and string to logical. The time and date did not seem
  86.   worth the effort, given the variety of possible inputs.
  87.  
  88.   As a final note, if you use any of the routines for IEEE single or double
  89.   types you will need to compile your program with the $N+ and $E+ compiler
  90.   directives.
  91. }
  92.  
  93.  
  94. {* String to Data conversion routines *}
  95.  
  96. Function StrToInteger(    S    : String;
  97.                       var Int;
  98.                           Size : Byte): Boolean;
  99.  
  100. Function StrToUnsigned(    S    : String;
  101.                        var Int;
  102.                            Size : Byte): Boolean;
  103.  
  104. Procedure StrToLString(    S : String;
  105.                        var Str);
  106.  
  107. Procedure StrToZString(    S : String;
  108.                        var Str);
  109.  
  110. Function StrToFloat(    S    : String;
  111.                     var Float;
  112.                         Size : Byte): Boolean;
  113.  
  114. Procedure StrToString(    S : String;
  115.                       var Str);
  116.  
  117. Function StrToBFloat(    S    : String;
  118.                      var BFloat;
  119.                          Size : Byte): Boolean;
  120.  
  121. Procedure StrToNumeric(    S    : String;
  122.                        var Numeric;
  123.                            Size : Byte);
  124.  
  125. Function StrToDecimal(    S    : String;
  126.                       var Decimal;
  127.                           Size : Byte): Boolean;
  128.   { The sign, negatives only, must be in first position, i.e. -1111.00
  129.     Make sure the decimal is big enough to hold the converted string!!!
  130.   }
  131.  
  132.  
  133.  
  134. {* Data to string conversion routines *}
  135.  
  136. Function LogicalToStr(var Logical;
  137.                           Size  : Byte): String;
  138.  
  139. Function IntegerToStr(var Int;
  140.                           Size : Byte;
  141.                           Width: Byte): String;
  142.  
  143. Function UnsignedToStr(var Int;
  144.                            Size : Byte;
  145.                            Width: Byte): String;
  146.  
  147. Function LStringToStr(var Str): String;
  148.  
  149. Function ZStringToStr(var Str): String;
  150.  
  151. Function TimeToStr(var Time): String;
  152.  
  153. Function DateToStr(var Date): String;
  154.  
  155. Function FloatToStr(var Float;
  156.                         Size    : Byte;
  157.                         Width   : Byte;
  158.                         Decimals: Byte): String;
  159.  
  160. Function StringToStr(var Str;
  161.                          Size : Byte): String;
  162.  
  163. Function DecimalToStr(var Decimal;
  164.                           Size : Byte): String;
  165.  
  166. Function BFloatToStr(var BFloat;
  167.                          Size    : Byte;
  168.                          Width   : Byte;
  169.                          Decimals: Byte): String;
  170.  
  171. Function NumericToStr(var Numeric;
  172.                           Size   : Byte): String;
  173.  
  174.  
  175.  
  176. {* BFloat conversion routines *}
  177.  
  178. Function BFloatToSingle(var BFloat): Single;
  179.   {- MS Single Precision (4 Byte) Float to TP IEEE Single }
  180.  
  181. Procedure SingleToBFloat(var BFloat;
  182.                              Sgl   : Single);
  183.   {- TP IEEE Single to MS Single Precision (4 Byte) Float }
  184.  
  185.  
  186. Function BFloatToDouble(var BFloat): Double;
  187.   {- MS Double precision (8 Byte) to TP IEEE Double }
  188.  
  189. Procedure DoubleToBFloat(var BFloat;
  190.                              Dbl   : Double);
  191.   {- TP IEEE Double to MS Double Precision (8 Byte) Float }
  192.  
  193.  
  194.  
  195. CONST
  196.   DecimalPt : Char  = '.';
  197.  
  198.