John Dammeyer wrote:
Delphi 5.
I'm working with National Instruments ActiveX controls and specifically
their CWGraph.ChartY function.
I'd like to chart two traces but I can't figure out how to make up a two
dimensional array to pass to the function.
Here's what I have to plot one trace:
ClippedArray : array of Variant; // Definition.
...
ClippedArray := VarArrayCreate([0,SAMPLE_SIZE],varVariant); //
Creation.
That's not right. VarArrayCreate returns a COM variant array. That is,
it returns a value of type Variant that happens to hold an array. It
does *not* return a Delphi dynamic array of Variants.
I guess the RTL knows how to assign a Variant to a dynamic array, so
your call to VarArrayCreate doesn't really do much. You create a variant
array and then you convert it to a dynamic array. You may as well just
call SetLength:
SetLength(ClippedArray, Sample_Size);
ClippedArray[k] := data; // data added to array.
...
FilteredDataGraph.chartY( ClippedArray ); // Data displayed on chart.
And it looks like the RTL also knows how to convert the other way, so
the compiler has automatically inserted additional code to create a
*new* variant array.
Since National Instruments doesn't really support Delphi I can't find
anything that points me in the right direction.
To make a multidimensional variant array, you need to pass *all* the
dimensions to VarArrayCreate.
var
DualArray: Variant;
DualArray := VarArrayCreate([0, 2, 0, Sample_Size], varVariant);
But, since we know the compiler can convert dynamic arrays to variant
arrays by itself, let's skip the VarArrayCreate call and just use an
ordinary dynamic array.
var
DualArray: array of array of Variant;
SetLength(DualArray, 2, Sample_Size);
Then pass it to the ChartY function as before.
--
Rob
_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi