EZ Jcom

Java to COM/ActiveX Bridge

Working with multi-dimensional arrays

COM supports arrays with multiple-dimensions, for instance an array of 4 dimensions which might be declared in Java as


int[][][][] myArray = new int[8][7][6][10];


EZ JCom supports multi-dimensional COM arrays passed via COM VARIANT objects (corresponding to the ezjcom.JComVariant class.)  Arrays can both be retrieved from COM as well as be sent to COM.

The method JComVariant.isMultiDimensionalArray() can be used to check if the variant contains a multi-dimensional array, and the method JComVariant.getNumberOfArrayDimensions() can be used to return the number of dimensions.

The method JComVariant.getMultiDimensionalArray() can be used to retrieve the array itself.  Note that the return type is “Object”, and the returned object must be cast to the appropriate type, e.g.

int[][][][] myArray = (int[][][][]) myVariant.getMultiDimensionalArray();

To initialize a variant to a particular multi-dimensional array for passing to COM, call the method JComVariant.setMultiDimensionalArray(), e.g.

JComVariant myVariant = new JComVariant();
int[][][][] myArray = new int[8][7][6][10];
/* Array initialization code goes here */
myVariant.setMultiDimensionalArray( myArray );