Board index » cppbuilder » Variant - TVariant

Variant - TVariant

I will ask about TVariant and Variant Types...

I want to pass from Client to Server some integers values...
I am trying to create a Variant (as Array of varInteger values) and pass
it to Server but
some problems occured...These problems are new since i install the
C++Builder4.
In C++Builder3 all the above works correctly..

More spesific the message that i get is that "Variant is not an
Array!!!"
The variant variable has lose it's type and has type with number "3".

I use the below code:

Client Side:
-----------------
    int Bounds1[2]={0, PageHits-1};
    Variant v_RecIds = VarArrayCreate(Bounds1, 1, varInteger);
    for (int i=0; i<PageHits; i++)
        v_RecIds.PutElement(i);
   Variant Result =
ClientDM->MIDASConnection->AppServer.Exec(Function("GetResultPage") <<
v_RecIds);

Server Side
--------------------
STDMETHODIMP TABEKT_iPAC_RModuleImpl::GetResultPage(TVariant RecordIDs,
  TVariant* Docs)
{
    try
    {
        Variant V(RecordIDs);
        NumRecords = V.ArrayHighBound(1);  ---->Error: Variant is not an
Array!!! Why?
        ...
        ...
        ...
    }
    catch(Exception &e)
    {
        delete pResults;
        return Error(e.Message.c_str(), IID_IABEKT_iPAC_RModule);
    }
    return S_OK;

Quote
};

How i solve this problem?
How is the right way for this?(and general how is the way to pass
Variants from Client to Server?)
The opposite way HAS NO PROBLEM!
 

Re:Variant - TVariant


Panagiotis L. Staikos <psta...@ekt.gr> wrote in message
news:378477EB.60B59689@ekt.gr...

Quote
> I will ask about TVariant and Variant Types...

> I want to pass from Client to Server some integers values...
> I am trying to create a Variant (as Array of varInteger values) and pass
> it to Server but
> some problems occured...These problems are new since i install the
> C++Builder4.
> In C++Builder3 all the above works correctly..

Just a wild guess,
BCB4 uses TVariant for automation params. There seems to be a bug when using
TVariant because it destroys the underlying VARIANT when TVariant goes out
of scope. This was the cause of errors in my app. I don't know if this has
anything to do with your problem but perhaps you can check the VCL code.
I only have the professionel version so I can not check it for you.

Good luck,

Martijn Brinkers

Re:Variant - TVariant


Quote
Panagiotis L. Staikos wrote in message <378477EB.60B59...@ekt.gr>...
>I want to pass from Client to Server some integers values...
>I am trying to create a Variant (as Array of varInteger values) and pass
>it to Server but some problems occured...These problems are new since i
install the
>C++Builder4. >In C++Builder3 all the above works correctly..

Well, something very similar happened to me - but in BCB 3.  I have a suite
of Delphi programs which communicate via COM, and the client passes data to
the server as a variant array of byte, as recommended as the fastest way to
get binary data across the process barrier.   I have now being training a
BCB 3 program to offer the same interface as the Delphi program, and tried
to use VarArrayLock() on the variant parameter.  Well, it was a reference!
So I extracted the reference variant, which was an array, and successfully
called VarArrayLock().  But when I was finished with the pointer, I was
unable to call VarArrayUnlock() with the _same variant_ without being told
that 'Variant is not an array'.  Very curious, since the value didn't
change.

I wonder if this has something to do with the construction/destruction
issues involved with variants? Do note that I am using VARIANT and not
TVariant or Variant.

Steve Donovan,
Mining Technology, CSIR South Africa

Re:Variant - TVariant


I still have this problem. Did you find any workaround???

Thanks
Redgo

Panagiotis L. Staikos <psta...@ekt.gr> wrote in message
news:378477EB.60B59689@ekt.gr...

Quote
> I will ask about TVariant and Variant Types...

> I want to pass from Client to Server some integers values...
> I am trying to create a Variant (as Array of varInteger values) and pass
> it to Server but
> some problems occured...These problems are new since i install the
> C++Builder4.
> In C++Builder3 all the above works correctly..

> More spesific the message that i get is that "Variant is not an
> Array!!!"
> The variant variable has lose it's type and has type with number "3".

> I use the below code:

> Client Side:
> -----------------
>     int Bounds1[2]={0, PageHits-1};
>     Variant v_RecIds = VarArrayCreate(Bounds1, 1, varInteger);
>     for (int i=0; i<PageHits; i++)
>         v_RecIds.PutElement(i);
>    Variant Result =
> ClientDM->MIDASConnection->AppServer.Exec(Function("GetResultPage") <<
> v_RecIds);

> Server Side
> --------------------
> STDMETHODIMP TABEKT_iPAC_RModuleImpl::GetResultPage(TVariant RecordIDs,
>   TVariant* Docs)
> {
>     try
>     {
>         Variant V(RecordIDs);
>         NumRecords = V.ArrayHighBound(1);  ---->Error: Variant is not an
> Array!!! Why?
>         ...
>         ...
>         ...
>     }
>     catch(Exception &e)
>     {
>         delete pResults;
>         return Error(e.Message.c_str(), IID_IABEKT_iPAC_RModule);
>     }
>     return S_OK;
> };

> How i solve this problem?
> How is the right way for this?(and general how is the way to pass
> Variants from Client to Server?)
> The opposite way HAS NO PROBLEM!

Re:Variant - TVariant


I did not find any solution....
i pass a AnsiString Str where Str has format (e.g 3_12_56_5) when
i should sent to server the record id's 3,12,56,5 and at the server
side i check for the underscores and i get the numbers....

In C++Builder3 this was too simple....
I hope to find a solution or if it is a bug i hope  Borland fix it...

Quote
Redgo wrote:
> I still have this problem. Did you find any workaround???

> Thanks
> Redgo

> Panagiotis L. Staikos <psta...@ekt.gr> wrote in message
> news:378477EB.60B59689@ekt.gr...
> > I will ask about TVariant and Variant Types...

> > I want to pass from Client to Server some integers values...
> > I am trying to create a Variant (as Array of varInteger values) and pass
> > it to Server but
> > some problems occured...These problems are new since i install the
> > C++Builder4.
> > In C++Builder3 all the above works correctly..

> > More spesific the message that i get is that "Variant is not an
> > Array!!!"
> > The variant variable has lose it's type and has type with number "3".

> > I use the below code:

> > Client Side:
> > -----------------
> >     int Bounds1[2]={0, PageHits-1};
> >     Variant v_RecIds = VarArrayCreate(Bounds1, 1, varInteger);
> >     for (int i=0; i<PageHits; i++)
> >         v_RecIds.PutElement(i);
> >    Variant Result =
> > ClientDM->MIDASConnection->AppServer.Exec(Function("GetResultPage") <<
> > v_RecIds);

> > Server Side
> > --------------------
> > STDMETHODIMP TABEKT_iPAC_RModuleImpl::GetResultPage(TVariant RecordIDs,
> >   TVariant* Docs)
> > {
> >     try
> >     {
> >         Variant V(RecordIDs);
> >         NumRecords = V.ArrayHighBound(1);  ---->Error: Variant is not an
> > Array!!! Why?
> >         ...
> >         ...
> >         ...
> >     }
> >     catch(Exception &e)
> >     {
> >         delete pResults;
> >         return Error(e.Message.c_str(), IID_IABEKT_iPAC_RModule);
> >     }
> >     return S_OK;
> > };

> > How i solve this problem?
> > How is the right way for this?(and general how is the way to pass
> > Variants from Client to Server?)
> > The opposite way HAS NO PROBLEM!

Other Threads