home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR36
/
BTV200.ZIP
/
BTVTYPE.INT
< prev
next >
Wrap
Text File
|
1993-12-18
|
6KB
|
198 lines
{*
*=========================================================================
* BTVTYPE.PAS Version 2.0
*
* BTRIEVE data type conversion routines for Turbo Pascal 6.0.
*
* Copyright (c) 1993 by Richard W. Hansen, all rights reserved.
*
*
* Requires Turbo Pascal version 6.0
*
*
* Registration and payment of a license fee is required for any use, whether
* in whole or part, of this source code.
*=========================================================================
*
*}
{****************************************************************************}
{* REVISION HISTORY *}
{* *}
{* Date Who What *}
{* ======================================================================== *}
{* 06/05/92 RWH First version. *}
{* 09/07/93 RWH Month and Day were backwards in BDateRec *}
{****************************************************************************}
UNIT BTVType;
{$F-}
{$X+}
{$A-}
{$V-}
{$N+,E+}
INTERFACE
TYPE
BDateRec = record
Day : Byte;
Month : Byte;
Year : Word;
end;
BTimeRec = record
Hundred : Byte;
Second : Byte;
Minute : Byte;
Hour : Byte;
end;
{
This Unit includes routines to convert Btrieve data types to and from
Pascal strings. Also included are routines for converting the BFloat types
to Turbo Pascal Singles, and Doubles.
These routines are intended to ease the use of the Btrieve data types.
At first, some of them may seem redundant or of little use. They are
designed primarily for use with raw data from Btrieve records. All the
routines use untyped VAR parameters to handle the Btrieve types that are
not defined in Pascal. Untyped VAR parameters get around Pascal's strict
type checking, so you should exercise a bit more care calling these
routines.
A typical call to convert IEEE single to a string might be:
St := FloatToStr(Buffer[10], 4, 10, 4);
Notice how the untyped parameter lets you convert data from any part of a
record buffer (though you could just as well have passed a variable of
type single in this example). Most of the routines have a size parameter,
in the example above it is the second parameter (4). The 4 indicates that
we want to convert a 4 byte Single into a string.
It is very important that you pass the correct size. The size always refers
to the size of the Btrieve type and controls the type conversion (say to
single or double) or the size of resulting data when converting from a
string to a Btrieve type. If you specify the size incorrectly, you will
get garbage results or overwrite other data in memory.
There are a couple of conversion routines left out, string to time and
string to date, and string to logical. The time and date did not seem
worth the effort, given the variety of possible inputs.
As a final note, if you use any of the routines for IEEE single or double
types you will need to compile your program with the $N+ and $E+ compiler
directives.
}
{* String to Data conversion routines *}
Function StrToInteger( S : String;
var Int;
Size : Byte): Boolean;
Function StrToUnsigned( S : String;
var Int;
Size : Byte): Boolean;
Procedure StrToLString( S : String;
var Str);
Procedure StrToZString( S : String;
var Str);
Function StrToFloat( S : String;
var Float;
Size : Byte): Boolean;
Procedure StrToString( S : String;
var Str);
Function StrToBFloat( S : String;
var BFloat;
Size : Byte): Boolean;
Procedure StrToNumeric( S : String;
var Numeric;
Size : Byte);
Function StrToDecimal( S : String;
var Decimal;
Size : Byte): Boolean;
{ The sign, negatives only, must be in first position, i.e. -1111.00
Make sure the decimal is big enough to hold the converted string!!!
}
{* Data to string conversion routines *}
Function LogicalToStr(var Logical;
Size : Byte): String;
Function IntegerToStr(var Int;
Size : Byte;
Width: Byte): String;
Function UnsignedToStr(var Int;
Size : Byte;
Width: Byte): String;
Function LStringToStr(var Str): String;
Function ZStringToStr(var Str): String;
Function TimeToStr(var Time): String;
Function DateToStr(var Date): String;
Function FloatToStr(var Float;
Size : Byte;
Width : Byte;
Decimals: Byte): String;
Function StringToStr(var Str;
Size : Byte): String;
Function DecimalToStr(var Decimal;
Size : Byte): String;
Function BFloatToStr(var BFloat;
Size : Byte;
Width : Byte;
Decimals: Byte): String;
Function NumericToStr(var Numeric;
Size : Byte): String;
{* BFloat conversion routines *}
Function BFloatToSingle(var BFloat): Single;
{- MS Single Precision (4 Byte) Float to TP IEEE Single }
Procedure SingleToBFloat(var BFloat;
Sgl : Single);
{- TP IEEE Single to MS Single Precision (4 Byte) Float }
Function BFloatToDouble(var BFloat): Double;
{- MS Double precision (8 Byte) to TP IEEE Double }
Procedure DoubleToBFloat(var BFloat;
Dbl : Double);
{- TP IEEE Double to MS Double Precision (8 Byte) Float }
CONST
DecimalPt : Char = '.';