Board index » cppbuilder » TSafeArray setup

TSafeArray setup


2006-11-12 02:09:38 AM
cppbuilder79
In my code I have two different ways to setup TSafeArray. They both seem to
work. I want to standardize all these setups. The two methods seen below
setup an arrary named ChartList. Are these setup methods both the same?
Which one is correct?
//Method 1
TSafeArrayDim1 DimChartList(0);
TSafeArrayBSTR1 ChartListNames(DimChartList);
//Method 2
TSafeArrayDim1 DimChartList(1);
TSafeArrayBSTR1 ChartList(0);
 
 

Re:TSafeArray setup

Hello Larry,
The recommended setup is one where the TSafeArray template is passed the
dimension. IOW, method #1. I took a peek at some of the unit test for this
class:
TSafeArrayDim1 dim(10);
TSafeArrayBSTR1 bstrArray(dim);
or
TSafeArrayDim2 dim(9, 5);
TSafeArrayInt2 intArray(dim);
etc...
Cheers,
Bruneau.
 

Re:TSafeArray setup

I noticed that you used the named "TSafeArrayInt2". My TSafeArray's always
use the number "1" such as "TSafeArrayDim1" and always "TSafeArrayBSTR1"
and always "TSafeArrayLong1". See my 1 dimensional arrays below. Is this OK
or do I need to sequence the TSafeArray's 1, 2, 3, 4, 5 and so on.
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrA(dim);
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrB(dim);
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrC(dim);
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrD(dim);
TSafeArrayDim1 dim(1)
TSafeArrayLong1 MylongE(dim);
Thanks
Larry
"Jean-Marie Babet" < XXXX@XXXXX.COM >wrote in message
Quote
Hello Larry,
 

{smallsort}

Re:TSafeArray setup

What is the difference between TSafeArrayDim1 Dim(0); and TSafeArrayDim1
Dim(1); ?
I thought that TSafeArrayDim1 Dim(0); would generate an error but it does
not.
Thanks
Larry.
"Jean-Marie Babet" < XXXX@XXXXX.COM >wrote in message
Quote
Hello Larry,

 

Re:TSafeArray setup

"LarryJ" < XXXX@XXXXX.COM >wrote in message
Quote
I noticed that you used the named "TSafeArrayInt2". My TSafeArray's
always use the number "1" such as "TSafeArrayDim1" and always
"TSafeArrayBSTR1" and always "TSafeArrayLong1". See my 1
dimensional arrays below. Is this OK or do I need to sequence the
TSafeArray's 1, 2, 3, 4, 5 and so on.
The number in the type names always refer to the number of dimensions the
array will have.
Quote
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrA(dim);
1-dimensional array with 1 BSTR element.
Quote
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrB(dim);
1-dimensional array with 1 BSTR element.
Quote
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrC(dim);
1-dimensional array with 1 BSTR element.
Quote
TSafeArrayDim1 dim(1)
TSafeArrayBSTR1 MybstrD(dim);
1-dimensional array with 1 BSTR element.
Quote
TSafeArrayDim1 dim(1)
TSafeArrayLong1 MylongE(dim);
1-dimensional array with 1 LONG element.
Gambit
 

Re:TSafeArray setup

"LarryJ" < XXXX@XXXXX.COM >wrote in message
Quote
What is the difference between TSafeArrayDim1 Dim(0);
and TSafeArrayDim1 Dim(1); ?
The first is declaring that there will be 0 elements in the array. The
second will have 1 element.
Quote
I thought that TSafeArrayDim1 Dim(0); would generate an error
but it does not.
It is not supposed to.
Please actually look inside of safearry.h. Everything you need to know is
in it. You will see exactly how the arrays are actually implemented.
Gambit