Board index » cppbuilder » BCB5 - ActiveX (Variant vs TVariant) using ComponentWorks

BCB5 - ActiveX (Variant vs TVariant) using ComponentWorks

Hi,

I am using National Instruments "ComponentWorks" which is an ActiveX
library, containing visual graph controls such as Graphs, LED's etc.

The graph component has a method called PlotY which according to the
documentation (and the type library) has the following definition:

   PlotY( Variant yData,
          Variant xFirst = 0,
          Variant xInc = 1,
          bPlotPerRow = true );

In the *ControlLib_OCX.h file, generated by the ActiveX import utility
the parameters has changed from type Variant to TVariant, as follows:

   PlotY( TVariant yData,
          TVariant xFirst/*[opt]*/= TNoParam(),
          TVariant xInc/*[opt]*/= TNoParam(),
          TVariant bPlotPerRow/*[opt]*/= TNoParam());

My initial fix to this, was to create a TVariant, to which I assigned
my Variant. This TVariant is then passed to the PlotY function:

  TVariant varDispT(varDispArray);             // Convert from Variant
(varDispArray) to TVariant

  plotControl->PlotY( varDispT, 0, 1, true );  // Plot data

Running the program with the BCB IDE works fine, but when I execute the
program from the
desktop of NT (Windows 2000), it crashes with an error message telling
me that an invalid
Variant operation has taken place.
Furhtermore, when the program is executed from within the IDE, the
BCB.EXE program, according
to Task Manager, has a memory leak, thus adding up used memory.

Can anyone help me on this subject?

Thank you in advance,

Bent Christensen
Unigate Technologies

b...@unigate.com

 

Re:BCB5 - ActiveX (Variant vs TVariant) using ComponentWorks


Bent, please don't use HTML when posting to this news server. Many
newsreaders can't handle it.

The TVariant is a wrapper around VARIANT, so you can call the method
passing regular values to it. The compiler will take care of wrapping
them ( rather, converting them ) to the appropriate type.

HTH,
Alex

Quote
Bent Christensen wrote:

[snip]

Re:BCB5 - ActiveX (Variant vs TVariant) using ComponentWorks


Thanks for the reply. Sorry about the format.

Your suggestion works fine as long as I use single regular values.
However, I
need to pass an array to the function PlotY which should be of type
Variant.
If I pass a Variant array to the function I get a compiler error. The
only workaround
I found is listed below. As mentioned earlier, this works fine as long as
the program
is executed within the BCB5 IDE, but when executed from the shell, the
program
fail/crashes with the statement "Invalid Variant Operation".

  Variant varDispArray = VarArrayCreate( OPENARRAY( int, ( 0, iSize) ),
varDouble );

  double* padDisp = (double*) varDispArray.ArrayLock();

  for( int i=0; i<iSize; i++ ) {
    padDisp[i] = (double)pawArray[i];
  }
  varDispArray.ArrayUnlock();

  TVariant varDispT(varDispArray);

  plotControl->PlotY( varDispT, 0, 1, true );

Best regards,

Bent Christensen

Quote
"Alex Bakaev [TeamB]" wrote:
> Bent, please don't use HTML when posting to this news server. Many
> newsreaders can't handle it.

> The TVariant is a wrapper around VARIANT, so you can call the method
> passing regular values to it. The compiler will take care of wrapping
> them ( rather, converting them ) to the appropriate type.

> HTH,
> Alex

> Bent Christensen wrote:
> [snip]

Other Threads