COMVariant.new Method

Initializes a new instance of the Object class.

Syntax

public void new([COMVariantInOut inOutFlag, COMVariantType type])

Run On

Called

Parameters

  • 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:
  • type
    Type: COMVariantType Enumeration
    A type of data to store; optional.
    These are the possible values that are supplied by the COMVariantType system enum:

Remarks

If the type parameter is omitted, no internal memory will be allocated until it is needed by one of the property methods of the COMVariant object. For a list of the property methods, see .

You can change the variant data type after it has been set by passing in a new value of a different type (by using one of the property methods).

The data types that are defined by the COMVariantType enum are equivalent to the variant data types that are defined by the Win32 SDK.

Examples

The following example creates three COMVariant objects:

  • varIn is for passing data to a COM method; it has a string stored in it and then a short (integer).

  • varOut is to receive data of type VT_I4 (long).

  • varOutRetval can pass in or receive data; its data type can be set by the COMDispFunction.call method.

{ 
    COMVariant varIn  = new COMVariant(); 
    COMVariant varOut = new COMVariant( 
        COMVariantInOut::OUT,  
        COMVariantType::VT_I4); 
    COMVariant varOutRetval = new COMVariant( 
        COMVariantInOut::OUT_RETVAL); ; 
  
    // Store a text string in the varIn object 
    varIn.bStr("Hello World"); 
  
    // Change varIn to a short. 
    // Text string stored in varIn is automatically released 
    varIn.short(123);  
}

See Also

COMVariant Class

COMVariant.variantInOutFlag Method

COMVariant.variantType Method

COMVariantType Enumeration