RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Variants.VarType Function

Returns the type code of a specified variant.

Pascal
function VarType(const V: Variant): TVarType;
C++
TVarType VarType(const Variant V);

VarType returns the type code of the given variant. The resulting value is either the type code for a custom Variant type, or it is constructed from the constants declared in the System unit. 

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 defined in the System unit:

VarType 
Contents of variant 
The variant is Unassigned.  
The variant is Null.  
16-bit signed integer (type Smallint in Delphi, short in C++ ).  
32-bit signed integer (type Integer in Delphi, int in C++).  
Single-precision floating-point value (type Single in Delphi, float in C++).  
Double-precision floating-point value (type double).  
Currency floating-point value (type Currency).  
Date and time value (type TDateTime).  
Reference to a dynamically allocated UNICODE string.  
Reference to an Automation object (an IDispatch interface pointer).  
Operating system error code.  
16-bit boolean (type WordBool).  
A variant.  
Reference to an unknown object (an IInterface or IUnknown interface pointer).  
8-bit signed integer (type ShortInt in Delphi or signed char in C++)  
A Byte  
unsigned 16-bit value (Word)  
unsigned 32-bit value (type LongWord in Delphi or unsigned long in C++)  
64-bit signed integer (Int64 in Delphi or __int64 in C++)  
COM-compatible string.  
Reference to a dynamically allocated string (not COM compatible).  

The value returned by VarType corresponds to the VType field of a TVarData record. 

The type of a variant can be changed using VarAsType

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!