Delphi Object and Component Reference
TVarData type
See also
Delphi example
TVarData represents the internal structure of a Variant variable.
Unit
System (Delphi) or SysVari (C++)
Delphi syntax:
type
TVarArrayBound = packed record
ElementCount: Integer;
LowBound: Integer;
end;
TVarArrayBoundArray = array [0..0] of TVarArrayBound;
PVarArray = ^TVarArray;
TVarArray = packed record
DimCount: Word;
Flags: Word;
ElementSize: Integer;
LockCount: Integer;
Data: Pointer;
Bounds: TVarArrayBoundArray;
end;
TVarData = packed record
case Integer of
0: (VType: TVarType;
case Integer of
0: (Reserved1: Word;
case Integer of
0: (Reserved2, Reserved3: Word;
case Integer of
varSmallInt: (VSmallInt: SmallInt);
varInteger: (VInteger: Integer);
varSingle: (VSingle: Single);
varDouble: (VDouble: Double);
varCurrency: (VCurrency: Currency);
varDate: (VDate: TDateTime);
varOleStr: (VOleStr: PWideChar);
varDispatch: (VDispatch: Pointer);
varError: (VError: HRESULT);
varBoolean: (VBoolean: WordBool);
varUnknown: (VUnknown: Pointer);
varShortInt: (VShortInt: ShortInt);
varByte: (VByte: Byte);
varWord: (VWord: Word);
varLongWord: (VLongWord: LongWord);
varInt64: (VInt64: Int64);
varString: (VString: Pointer);
varAny: (VAny: Pointer);
varArray: (VArray: PVarArray);
varByRef: (VPointer: Pointer);
);
1: (VLongs: array[0..2] of LongInt);
);
2: (VWords: array [0..6] of Word);
3: (VBytes: array [0..13] of Byte);
);
1: (RawData: array [0..3] of LongInt);
end;
C++ syntax:
struct TVarData
{
union
{
uint16_t VType; // Delphi-compatible - Variant Type member
VARTYPE vt; //
tagVARIANT compatible member (Windows
only)
};
uint16_t Reserved1;
uint16_t Reserved2;
uint16_t Reserved3;
union
{
// Delphi-compatible Variant members
Smallint VSmallint; // iVal
Integer VInteger; // lVal
Single VSingle; // fltVal
Double VDouble; // dblVal
CurrencyBase VCurrency; // cyVal
TDateTimeBase VDate; // date
PWideChar VOleStr; // bstrVal
IDispatch* VDispatch; // pdispVal
HResult VError; // scode
WordBool VBoolean; // boolVal
IUnknown* VUnknown; // punkVal
Byte VByte; // bVal
Shortint VShortint; // charVal
Shortint VShortInt; // charVal
Pointer VString; // ??????
PVarArray VArray; // parray
Pointer VPointer; // byref
__int64 VInt64; // ????
Word VWord;
LongWord VLongWord;
//
tagVARIANT compatible members (from OAIDL.H)
// Allowing all types marked as [V] (may appear in a VARIANT to be
initialized)
// Windows Only
LONG lVal;
BYTE bVal;
SHORT iVal;
FLOAT fltVal;
DOUBLE dblVal;
VARIANT_BOOL boolVal;
SCODE scode;
CY cyVal;
DATE date;
BSTR bstrVal;
LONG64 llVal;
IUnknown *punkVal;
IDispatch *pdispVal;
SAFEARRAY *parray;
BYTE *pbVal;
SHORT *piVal;
LONG *plVal;
FLOAT *pfltVal;
DOUBLE *pdblVal;
VARIANT_BOOL *pboolVal;
SCODE *pscode;
CY *pcyVal;
DATE *pdate;
BSTR *pbstrVal;
IUnknown **ppunkVal;
IDispatch **ppdispVal;
SAFEARRAY **pparray;
VARIANT *pvarVal;
PVOID byref;
CHAR cVal;
USHORT uiVal;
ULONG ulVal;
INT intVal;
UINT uintVal;
DECIMAL *pdecVal;
CHAR *pcVal;
USHORT *puiVal;
ULONG *pulVal;
INT *pintVal;
UINT *puintVal;
LONG64 *pllVal;
};
}
Description
The TVarData type represents the internal structure of a Variant variable.
The VType field of a TVarData record contains the type code of the variant in the lower twelve bits
(the bits defined by the varTypeMask constant). In addition, the varArray bit may be set to indicate
that the Variant is an array, and the varByRef bit may be set to indicate that the Variant contains a
reference as opposed to a value.
The Reserved1, Reserved2, and Reserved3 fields of a TVarData record are unused.
The contents of the remaining eight bytes of a TVarData record depend on the VType field. If
neither the varArray nor the varByRef bits are set, the Variant contains a value of the given type.
This can be a predefined type or a custom Variant type.
If the varArray bit is set, the Variant contains a pointer to a TVarArray structure that defines the
specifics of the array. The type of each array element is given by the varTypeMask bits in the
VType field.
If the varByRef bit is set, the Variant contains a reference to a value of the type given by the
varTypeMask and varArray bits in the VType field.
The internal structure of a Variant is compatible with the Variant type used by COM and the
Win32 APIs. Note that the varString and varAny type codes are features of CLX and not are
not supported by COM or the Win32 APIs. Variants containing a varString value should
never be passed to a non-CLX function. Delphi's Automation support automatically converts
varString Variants to varOleStr variants before passing them as parameters to external
functions. Variants containing a varAny value should only be passed to CORBA functions.