Share via


COMVariant::createFromArray Method

Creates a new COMVariant object and initializes it with an array in one operation.

Syntax

client server public static COMVariant createFromArray(Array value, [COMVariantInOut inOutFlag])

Run On

Called

Parameters

  • value
    Type: Array Class
    The array used to initialize the object.
  • inOutFlag
    Type: COMVariantInOut Enumeration
    A flag that determines whether the object can be used to pass data to a COM method or COM property, to receive data, or both. This parameter is optional.
    Possible values are:

Return Value

Type: COMVariant Class
The new COMVariant object.

Remarks

The COMVariant object that is created by this method has the data type VT_SAFEARRAY (array).

You can change the data type of an existing COMVariant object to VT_SAFEARRAY by using the variantType method or by passing in an array value by using the safeArray property method.

Examples

The following example creates a new COMVariant object and initializes it with an array of integers.

{ 
    int i; 
    COMVariant var; 
    Array arr = new Array(Types::INTEGER); 
  
    for (i = 1; i <= 10; i++) 
        // Insert 10 values in the array 
        arr.value(i, i); 
  
    // Create and initialize a COMVariant object  
    var = COMVariant::createFromArray(arr); 
}

See Also

COMVariant Class

COMVariant.safeArray Method

Array Class

COMVariant.new Method