Board index » cppbuilder » Variant TVariant

Variant TVariant

Hello,

 this is what I found in the BcB4 help file:

If you have a VCL variant, Variant, and need to pass it to an Automation
Object expecting a TVariant, you'll need to use the VARIANT conversion
operator. The same applies in the other direction. For example,

VclFunction(const Variant& varParam);

OleServer(TVariant var);

Variant vclV;
TVariant tV;

VclFunction(VARIANT(tV));
OleServer(VARIANT(vclV));

I would like to use these functions, but which #include do I need for that?

 

Re:Variant TVariant


Greydanus,

The VARIANT() conversion operator is a member of both VCL's Variant and
TVariant. In other words, you can extract a raw VARIANT from either type
using VARIANT(aVclVariant) and VARIANT(aTVariantVariable). Then you create
the other encapsulated type from the raw VARIANT.

With hindsight I can say that we did not handle this in an elegant fashion.
We underestimated the amount of Code that's shuffling VCL's Variant style
data to and from ActiveX TVariant style variant.

The help page you mentioned is slightly out of date. Towards the end of the
cycle, we did become increasingly aware that OLE data was being passed into
VCL functions quite a bit (more and more beta testers were porting old code
that would break). OLE Server/Client code dealing with TVariant would need
to call VCL routines expecting  a Variant. We did add constructor,
assignment operator, and conversion operator in System::Variant [SYSVARI.H]
to know about TVariant. So to pass a TVariant to a function expecting a
Variant is transparent:

      void  AFunction(const Variant& var);
      void  BFUnction(Variant var);

      TVariant tv;
      AFunction(tv);
      BFunction(tv);

Although requested to do so, we refrained to go the other way (I've
explained the reasons before: to leave the option to do a light-weight,
VCL-less ActiveX implementation in the future). Since the TVariant()
conversion operator is already in Variant, the compiler knows how to convert
a Variant to a TVariant. However, the operation is ambiguous (because the
compiler could convert the Variant to other types form which a TVariant can
be constructed). So you need to request the Variant to go through the simple
TVariant() operator:

      void AFunction(const TVariant& var):
      void BFunction(TVariant var)

      Variant v;
       AFunction(TVariant(v));
       BFunction(TVariant(v));

Assignments and constructions are the same:
       v = tv;                      // Transparent
       Variant v2(tv);        // Transparent

       tv = TVariant(v);                    // Via Variant.operator
TVariant()
       TVariant tv2(TVariant(v));    // Via Variant.operator TVariant()

Hope the above helps,

Bruneau.

Quote
Greydanus wrote in message <927797440.151...@dibbs3.eur.cis.philips.com>...
>Hello,

> this is what I found in the BcB4 help file:

>If you have a VCL variant, Variant, and need to pass it to an Automation
>Object expecting a TVariant, you'll need to use the VARIANT conversion
>operator. The same applies in the other direction. For example,

>VclFunction(const Variant& varParam);

>OleServer(TVariant var);

>Variant vclV;
>TVariant tV;

>VclFunction(VARIANT(tV));
>OleServer(VARIANT(vclV));

>I would like to use these functions, but which #include do I need for that?

Other Threads