RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.TVarData Record

TVarData represents Variant information.

Pascal
TVarData = packed record
  case Integer of
    0: (VType: TVarType;
        Reserved1: Word;
        Reserved2: Word;
        Reserved3: Word;);
    1: (VLongs: array[0..2] of LongInt);
        RawData: array [0..3] of LongInt););
    2: (VWords: array [0..6] of Word);
        VBytes: array [0..13] of Byte););
    varAny: (VAny: Pointer;);
    varArray: (VArray: PVarArray;);
    varBoolean: (VBoolean: WordBool;);
    varByRef: (VPointer: Pointer;);
    varByte: (VByte: Byte;);
    varCurrency: (VCurrency: Currency;);
    varDate: (VDate: TDateTime;);
    varDispatch: (VDispatch: Pointer;);
    varDouble: (VDouble: Double;);
    varError: (VError: HRESULT;);
    varInt64: (VInt64: Int64;);
    varInteger: (VInteger: Integer;);
    varLongWord: (VLongWord: LongWord;);
    varOleStr: (VOleStr: PWideChar;);
    varShortInt: (VShortInt: ShortInt;);
    varSingle: (VSingle: Single;);
    varSmallInt: (VSmallInt: SmallInt;);
    varString: (VString: Pointer;);
    varUnknown: (VUnknown: Pointer;);
    varWord: (VWord: Word;);
end;
C++
struct TVarData {
  TVarType VType;
  Word Reserved1;
  Word Reserved2;
  Word Reserved3;
  SmallInt VSmallInt;
  int VInteger;
  Single VSingle;
  Double VDouble;
  Currency VCurrency;
  TDateTime VDate;
  PWideChar VOleStr;
  void * VDispatch;
  HRESULT VError;
  WordBool VBoolean;
  void * VUnknown;
  ShortInt VShortInt;
  Byte VByte;
  Word VWord;
  LongWord VLongWord;
  Int64 VInt64;
  void * VString;
  void * VAny;
  PVarArray VArray;
  void * VPointer;
  array[0..2] of LongInt) VLongs;
  array [0..6] of Word) VWords;
  array [0..13] of Byte) VBytes;
  array [0..3] of LongInt) RawData;
};

System

TVarData is the base class for Variant.

Note: The internal structure of a Variant as designated by TVarData is identical to the Variant type used by OLE and the Win32 APIs.
struct TVarData

  {
union
    {
      Word     VType;    // Delphi-compatible - Variant Type member
      VARTYPE  vt;       // tagVARIANT compatible member
    };
    Word Reserved1;
    Word Reserved2;
    Word 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
      Pointer       VString;      //  ??????
      PVarArray     VArray;       //  parray
      Pointer       VPointer;     //  byref
      // tagVARIANT compatible members (from OAIDL.H)
      // Allowing all types marked as [V] (may appear in a VARIANT to be initialized
      LONG          lVal;
      BYTE          bVal;
      SHORT         iVal;
      FLOAT         fltVal;
      DOUBLE        dblVal;
      VARIANT_BOOL  boolVal;
      SCODE         scode;
      CY            cyVal;
      DATE          date;
      BSTR          bstrVal;
      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;
    };
  };

The VType of TVarData contains the type code of the variant in the lower twelve bits (the bits defined by varTypeMask). 

The following values are used for VType: 

#define varEmpty (Byte)(0)

#define varNull (ByteByte_Type)(1)
#define varSmallint (ByteByte_Type)(2)
#define varInteger (ByteByte_Type)(3)
#define varSingle (ByteByte_Type)(4)
#define varDouble (ByteByte_Type)(5)
#define varCurrency (ByteByte_Type)(6)
#define varDate (ByteByte_Type)(7)
#define varOleStr (ByteByte_Type)(8)
#define varDispatch (ByteByte_Type)(9)
#define varError (ByteByte_Type)(10)
#define varBoolean (ByteByte_Type)(11)
#define varVariant (ByteByte_Type)(12)
#define varUnknown (ByteByte_Type)(13)
#define varByte (ByteByte_Type)(17)
#define varString (WordWord_Type)(256)
#define varTypeMask (WordWord_Type)(4095)
#define varArray (WordWord_Type)(8192)
#define varByRef (WordWord_Type)(16384)
#define varStrArg (ByteByte_Type)(72)
#define vtInteger (ByteByte_Type)(0)
#define vtBoolean (ByteByte_Type)(1)
#define vtChar (ByteByte_Type)(2)
#define vtExtended (ByteByte_Type)(3)
#define vtString (ByteByte_Type)(4)
#define vtPointer (ByteByte_Type)(5)
#define vtPChar (ByteByte_Type)(6)
#define vtObject (ByteByte_Type)(7)
#define vtClass (ByteByte_Type)(8)
#define vtWideChar (ByteByte_Type)(9)
#define vtPWideChar (ByteByte_Type)(10)
#define vtAnsiString (ByteByte_Type)(11)
#define vtCurrency (ByteByte_Type)(12)
#define vtVariant (ByteByte_Type)(13)

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. 

Word Reserved1;

    Word Reserved2;
    Word Reserved3;

The Reserved1, Reserved2, and Reserved3 members of TVarData are unused. 

union { Smallint VSmallint;

      Integer VInteger;
      Single VSingle;
      Double VDouble;
      CurrencyBase VCurrency;
      TDateTimeBase VDate;
      PWideChar VOleStr;
      Ole2::IDispatch* VDispatch;
      Integer VError;
      WordBool VBoolean;
      Ole2::IUnknown* VUnknown;
      Byte VByte;
      Pointer VString;
      PVarArray VArray;
      Pointer VPointer;
    };
};

The contents of the remaining eight bytes of TVarData depend on the VType field. If neither the varArray nor the varByRef bits are set, the variant contains a value of the given 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 VType. 

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 VType. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!