Board index » cppbuilder » I have a Variant - I need a TVariant

I have a Variant - I need a TVariant

Hello,

I am trying to use an imported ActiveX using the method where I use a
Variant and call methods like OlePropertySet and OleFunction, etc.

I create a Variant using CreateOleObject and set some properties.  Then
I need to pass the object to a property and a method of the ActiveX
control I dropped on the form.

   Variant param, ds;

   param = CreateOleObject("MapX.ODBCQueryInfo.3");

   param.OlePropertySet( "SqlQuery", "select * from USA" );
   param.OlePropertySet( "DataSource", "MapStatsV3" );
   param.OlePropertySet( "ConnectString", "ODBC" );

  ds = Map1->Datasets->Add( miDataSetODBC, param );  // line 38

The compile fails with the messages:

[C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
Variant::operator TVariant()' and TVariant::TVariantT(const Variant &)'

[C++ Error] MainForm.cpp(38): E2342 Type mismatch in parameter
'SourceData' (wanted 'TVariant', got 'Variant')

[C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
System::Variant::operator =(const bool)' and '_fastcall
System::Variant::operator =(IUnknown *)

I don't really understand these errors (except the second one).  Is
there a way to convert the Variant to a TVariant?

I may have completely misunderstood how I'm supposed to work with this
control.  If so, maybe someone can tell me.  I think I can get it to
work in Delphi;  I just prefer C++.

Thanks in advance

Hardee Mahoney
Washington, DC

 

Re:I have a Variant - I need a TVariant


Quote
Hardee & Juan wrote:

> Hello,

> I am trying to use an imported ActiveX using the method where I use a
> Variant and call methods like OlePropertySet and OleFunction, etc.

> I create a Variant using CreateOleObject and set some properties.  Then
> I need to pass the object to a property and a method of the ActiveX
> control I dropped on the form.

>    Variant param, ds;

>    param = CreateOleObject("MapX.ODBCQueryInfo.3");

>    param.OlePropertySet( "SqlQuery", "select * from USA" );
>    param.OlePropertySet( "DataSource", "MapStatsV3" );
>    param.OlePropertySet( "ConnectString", "ODBC" );

>   ds = Map1->Datasets->Add( miDataSetODBC, param );  // line 38

> The compile fails with the messages:

> [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> Variant::operator TVariant()' and TVariant::TVariantT(const Variant &)'

> [C++ Error] MainForm.cpp(38): E2342 Type mismatch in parameter
> 'SourceData' (wanted 'TVariant', got 'Variant')

> [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> System::Variant::operator =(const bool)' and '_fastcall
> System::Variant::operator =(IUnknown *)

> I don't really understand these errors (except the second one).  Is
> there a way to convert the Variant to a TVariant?

> I may have completely misunderstood how I'm supposed to work with this
> control.  If so, maybe someone can tell me.  I think I can get it to
> work in Delphi;  I just prefer C++.

> Thanks in advance

> Hardee Mahoney
> Washington, DC

Try doing the following with all of your strings:

  param = CreateOleObject( WideString( "MapX.ODBCQueryInfo.3" ) );

Paul Scott

Re:I have a Variant - I need a TVariant


Maybe you can create a TVariant from the Variant param:
TVariant V(param);
and give V to the method.

Wim.

Hardee & Juan <jsveg...@erols.com> schreef in berichtnieuws
3ABE5F48.3A143...@erols.com...

Quote
> Hello,

> I am trying to use an imported ActiveX using the method where I use
a
> Variant and call methods like OlePropertySet and OleFunction, etc.

> I create a Variant using CreateOleObject and set some properties.
Then
> I need to pass the object to a property and a method of the ActiveX
> control I dropped on the form.

>    Variant param, ds;

>    param = CreateOleObject("MapX.ODBCQueryInfo.3");

>    param.OlePropertySet( "SqlQuery", "select * from USA" );
>    param.OlePropertySet( "DataSource", "MapStatsV3" );
>    param.OlePropertySet( "ConnectString", "ODBC" );

>   ds = Map1->Datasets->Add( miDataSetODBC, param );  // line 38

> The compile fails with the messages:

> [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> Variant::operator TVariant()' and TVariant::TVariantT(const Variant
&)'

> [C++ Error] MainForm.cpp(38): E2342 Type mismatch in parameter
> 'SourceData' (wanted 'TVariant', got 'Variant')

> [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> System::Variant::operator =(const bool)' and '_fastcall
> System::Variant::operator =(IUnknown *)

> I don't really understand these errors (except the second one).  Is
> there a way to convert the Variant to a TVariant?

> I may have completely misunderstood how I'm supposed to work with
this
> control.  If so, maybe someone can tell me.  I think I can get it to
> work in Delphi;  I just prefer C++.

> Thanks in advance

> Hardee Mahoney
> Washington, DC

Re:I have a Variant - I need a TVariant


With this suggestion and a suggestion from Mark Cashman I tried the
following code:

   IDispatch *ID = param;
   TVariant TV = TVariant( ID );

   Map1->Datasets->Add( miDataSetODBC, TV, "odbc dataset" );

Now I get a runtime exception "Invalid Variant Type Conversion".

If anyone has any suggestions I would appreciate it.

Thanks again,

Hardee

Quote
Wim Bekker wrote:
> Maybe you can create a TVariant from the Variant param:
> TVariant V(param);
> and give V to the method.

> Wim.

> Hardee & Juan <jsveg...@erols.com> schreef in berichtnieuws
> 3ABE5F48.3A143...@erols.com...
> > Hello,

> > I am trying to use an imported ActiveX using the method where I use
> a
> > Variant and call methods like OlePropertySet and OleFunction, etc.

> > I create a Variant using CreateOleObject and set some properties.
> Then
> > I need to pass the object to a property and a method of the ActiveX
> > control I dropped on the form.

> >    Variant param, ds;

> >    param = CreateOleObject("MapX.ODBCQueryInfo.3");

> >    param.OlePropertySet( "SqlQuery", "select * from USA" );
> >    param.OlePropertySet( "DataSource", "MapStatsV3" );
> >    param.OlePropertySet( "ConnectString", "ODBC" );

> >   ds = Map1->Datasets->Add( miDataSetODBC, param );  // line 38

> > The compile fails with the messages:

> > [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> > Variant::operator TVariant()' and TVariant::TVariantT(const Variant
> &)'

> > [C++ Error] MainForm.cpp(38): E2342 Type mismatch in parameter
> > 'SourceData' (wanted 'TVariant', got 'Variant')

> > [C++ Error] MainForm.cpp(38): E2015 Ambiguity between '_fastcall
> > System::Variant::operator =(const bool)' and '_fastcall
> > System::Variant::operator =(IUnknown *)

> > I don't really understand these errors (except the second one).  Is
> > there a way to convert the Variant to a TVariant?

> > I may have completely misunderstood how I'm supposed to work with
> this
> > control.  If so, maybe someone can tell me.  I think I can get it to
> > work in Delphi;  I just prefer C++.

> > Thanks in advance

> > Hardee Mahoney
> > Washington, DC

Other Threads