Главная страница | назад

Article #19407: The Variant data type in BCB4

 Question and Answer Database

FAQ4407C.txt   :The Variant data type in BCB4
Category   :ActiveX/OLE/COM/ActiveForm
Platform    :All-32Bit
Product    :C++Builder4.x,   

Why doenst't the Variant type I used in BCB3 compile in BCB4?
Only a simple example about VARIANT argument:

STDMETHODIMP TProvaImpl::Method1(TVariant* Param1)
    Variant v;  *Param1 = v;  // No problems under BCB3


[C++ Error] ProvaImpl.cpp(15): E2015 Ambiguity between
'TVariantT::operator =(const TVariantT &)' and
'TVariantT::operator =(bool)'.

One of our goals in the project was to allow for the possibility, some
time down the road, of VCL-free COM/DCOM development. As a result, key
classes like TVariant don't know anything about VCL-bound classes
like Variant. (Variant is the C++ wrapper of the Delphi Variant type,
which wraps OLE's VARIANT; TVariant also wraps OLE's VARIANT, but without
the intervening level).

However, Variant was modified so that it has copy constructors, assignment 
operators, and cast operators for TVariant.

What's happening here is that you are saying:

Variant v;
TVariant Param1 = v;

And the compiler looks down the list of TVariant's assignment operators
and finds none that match type Variant, so then it looks down the list
of cast operators for Variant and finds two that TVariant has assignment
operators for, and can't choose between them --- what would be its basis
for choosing?

The solution is to do this:


or, better yet, to say

TVariant v;

in the first place [if you can; for some data-bound operations you can't.].

Note that as both encapsulate VARIANT the internal layout is the same,
so there is no issue with pointer slicing caused by the typecast I recommended. 

2/24/1999 2:04:29 PM

Last Modified: 01-SEP-99