Board index » cppbuilder » Variant/TVariant post patch nightmare

Variant/TVariant post patch nightmare

OK, I'm stuck (yet again on this {*word*76}y Variant thing, I wish wish
someone would make this data type easier to use).

Pre patch, the following code worked fine

    Variant channel, plot, null_var;
    null_var.VType = varNull;
    Variant select(OPENARRAY(int,(0,1)), varVariant);
    select.PutElement(null_var, 1);

    for(int index = 1; index <= no_active_chans; index++)
    {
        select.PutElement(index - 1, 0);    // select channel
        channel = CWArray->IndexArray(ScaledData, select);
    }

Now the compiler throws the follwing errors

[C++ Error] MainForm.cpp(506): E2015 Ambiguity between '_fastcall
Variant::operator TVariant()' and 'TVariant::TVariantT(const Variant
&)'.
[C++ Error] MainForm.cpp(506): E2343 Type mismatch in parameter
'IndexArray' in call to '_fastcall
TCWArray::IndexArray(TVariant,TVariant)'.

Now, TCWArray is an active X control from natinal instruments, and
IndexArray has the TVariant TCWArray::IndexArray(TVariant,TVariant)
where it takes a multi dimentional array and a TVariant that selects
which of these you want to return in a single dimensional array
(sounds complex, but shouldn't be).

I need to use LOTS of these as the NI controls use TVariant's
everywhere (they use to be Variants).

HELP....  I just don't understand the difference between TVariant,
Variant, VARIANT, and SafeArray.

TIA, (I hope).

Peter

 

Re:Variant/TVariant post patch nightmare


Peter, what happens when you change Variant channel,... to TVariant ?

Alex

Quote
Peter Nunn wrote:

[snip]

--
HotSend - portable documents technology
http://www.hotsend.com/
eFax - get your faxes via email - Free !
http://www.efax.com

Re:Variant/TVariant post patch nightmare


Same error...

Problem seems to be with the select variable.

Thanks to Peter Waldschmidt the following compiles

Variant channel, plot, null_var;
    null_var.VType = varNull;
    Variant select(OPENARRAY(int,(0,1)), varVariant);
    select.PutElement(null_var, 1);

    for(int index = 1; index <= no_active_chans; index++)
    {
        select.PutElement(index - 1, 0);    // select channel
        TVariant v(select);         <----- added this
        channel = CWArray->IndexArray(ScaledData, v);
    }

But what a messy way to have to do things.

Is there a better way?

On Tue, 03 Aug 1999 11:04:10 -0700, "Alex Bakaev [TeamB]"

Quote
<al...@jetsuite.com> wrote:
>Peter, what happens when you change Variant channel,... to TVariant ?

>Alex

>Peter Nunn wrote:
>[snip]

Re:Variant/TVariant post patch nightmare


OK, got that one fixed, now to the crunch.

What I really want to do is get to the data in the TVariant, put it
into a stl::valarray<float>, do some work and then put it back into
the TVariant again.

I have the following code that gets me to the data and into the
valarray (eventually) as follows

void __fastcall TForm1::CWAIAcquiredData(TObject *Sender,
      TVariant *ScaledData, TVariant *BinaryCodes)
{
    SAFEARRAY* safe = ScaledData->parray;
    float* pdata;
    HRESULT hr = SafeArrayAccessData(safe, (void**)&pdata);
    if(!FAILED(hr))
    {
        std::valarray<float> data_array(pdata,
sizeof(pdata)/sizeof(float));
    }
    SafeArrayUnaccessData(safe);

Quote
}

but I can't work out how to get the data out of the valarray in one
chunk to put it back again.

The second question is this, the code above looks horribly
inefficient.  Is there a quicker way of doing this?

TIA

Peter

On Tue, 03 Aug 1999 11:04:10 -0700, "Alex Bakaev [TeamB]"

Quote
<al...@jetsuite.com> wrote:
>Peter, what happens when you change Variant channel,... to TVariant ?

>Alex

>Peter Nunn wrote:
>[snip]

Other Threads