COMVariant.safeArray Method
Gets or sets the value of a COMVariant object of the VT_SAFEARRAY data type.
Syntax
public Array safeArray([Array newValue, COMVariantType newType])
Run On
Called
Parameters
- newValue
Type: Array Class
The new array; optional.
- newType
Type: COMVariantType Enumeration
The type of the new array; optional.
Return Value
Type: Array Class
The current array.
Remarks
If you pass in a value that has a different data type than the object, the data type of the object will be changed to match the data type of the value.
A COMVariant object has an array Boolean type if its data type is set to COMVariantType::VT_SAFEARRAY. A safe array is COM's equivalent to an array. Currently only one-dimensional safe arrays are supported.
Examples
The following example creates a new COMVariant object of type VT_SAFEARRAY and initializes it with an array of shorts.
{
int i, result;
COM com;
COMVariant var = new COMVariant(
COMVariantInOut::IN_OUT,
COMVariantType::VT_SAFEARRAY);
Array arr = new Array(Types::INTEGER);
// Insert 10 values in the array
for (i = 1; i <= 10; i++)
{
arr.value(i, i);
}
// Set value of the object and ensure the integer values
// are treated as short data types
var.safeArray(arr, COMVariantType::VT_I2);
}