Myosotis
Myosotis

Reputation: 388

Analogs of Delphi types in C/C++

What are analogues for Delphi types TVarType and OleVariant in C/C++ ?

Upvotes: 3

Views: 1152

Answers (3)

Remy Lebeau
Remy Lebeau

Reputation: 596121

If you are using C++Builder specifically, it has its own TVarType and OleVariant types that directly correlate with those Delphi types. TVarType is declared in System.hpp, and OleVariant is declared in systvari.h, just like the documentation you linked to says.

Upvotes: 0

Andriy
Andriy

Reputation: 8604

The equivalent of OleVariant is VARIANT structure which is wrapped in _variant_t Class in Visual C++.

The equivalent of TVarType is VARTYPE typedef, technically, it is unsigned short, but it holds values of VARENUM enumeration.

Upvotes: 4

enhzflep
enhzflep

Reputation: 13089

Well, clearly from their own documentation - the first is simply an unsigned word - a uint_16.

The second is a little more difficult to explain. It's basically a great big struct that contains a whole bunch of fields. This one data type includes a field for each data-type that could be transferred to/from a COM object. This means you just need to concern yourself with passing a variant to/from the object. It's then up to each of you (programmer/COM object) to extract/insert data at the relevant places.

Perhaps I shouldn't, but here's the definition for a VARIANT from oaidl.h (gcc, win32)

typedef struct tagVARIANT {
  _ANONYMOUS_UNION union {
    struct __tagVARIANT {
    VARTYPE vt;
    WORD wReserved1;
    WORD wReserved2;
    WORD wReserved3;
    _ANONYMOUS_UNION union {
        long lVal;
        LONGLONG llVal;
        unsigned char bVal;
        short iVal;
        float fltVal;
        double dblVal;
        VARIANT_BOOL  boolVal;
        SCODE scode;
        CY cyVal;
        DATE date;
        BSTR bstrVal;
        IUnknown *punkVal;
        LPDISPATCH pdispVal;
        SAFEARRAY *parray;
        unsigned char *pbVal;
        short *piVal;
        long *plVal;
        LONGLONG  * pllVal;
        float *pfltVal;
        double *pdblVal;
        VARIANT_BOOL *pboolVal;
        _VARIANT_BOOL  *pbool;
        SCODE *pscode;
        CY *pcyVal;
        DATE *pdate;
        BSTR *pbstrVal;
        IUnknown **ppunkVal;
        LPDISPATCH *ppdispVal;
        SAFEARRAY **pparray;
        struct tagVARIANT *pvarVal;
        void *byref;
        CHAR cVal;
        USHORT uiVal;
        ULONG ulVal;
        ULONGLONG ullVal;
        INT intVal;
        UINT uintVal;
        DECIMAL *pdecVal;
        CHAR  *pcVal;
        USHORT  *puiVal;
        ULONG  *pulVal;
        ULONGLONG * pullVal;
        INT  *pintVal;
        UINT  *puintVal;
        _ANONYMOUS_STRUCT struct {
            PVOID pvRecord;
            struct IRecordInfo *pRecInfo;
        } __VARIANT_NAME_4;
    } __VARIANT_NAME_3;
    } __VARIANT_NAME_2;
    DECIMAL decVal;
  } __VARIANT_NAME_1;
} VARIANT,*LPVARIANT;

Upvotes: 2

Related Questions