Returns the type code of a specified Variant.
Unit
System
Category
Variant support routines
function VarType(const V: Variant): Integer;
Description
VarType returns the type code of the given Variant. The resulting value is constructed from the following constants declared in the System unit.
const
varEmpty = $0000;
varNull = $0001;
varSmallint = $0002;
varInteger = $0003;
varSingle = $0004;
varDouble = $0005;
varCurrency = $0006;
varDate = $0007;
varOleStr = $0008;
varDispatch = $0009;
varError = $000A;
varBoolean = $000B;
varVariant = $000C;
varUnknown = $000D;
varByte = $0011;
varStrArg = $0048;
varString = $0100;
varAny = $0101;
varTypeMask = $0FFF;
varArray = $2000;
varByRef = $4000;
The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.
The following table describes the meaning of each of the Variant type codes.
VarType Contents of Variant
varEmpty The Variant is Unassigned.
varNull The Variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.
varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A Variant.
varUnknown Reference to an unknown OLE object (an IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.
The value returned by VarType corresponds to the VType field of a TVarData record.
The type of a Variant can be changed using VarAsType or VarCast.