Share via


COMVariant.noValue Method

Deletes the contents of an existing COMVariant object and enables it to act as an unspecified argument when it is used in the COMDispFunction.call method or the COM class.

Syntax

public void noValue()

Run On

Called

Remarks

A no-value variant can be used when a COM method has parameters that can be null. It indicates to the COM object that the argument has not been specified and that it must use its own default value.

When you are calling methods on a COM object, the unspecified argument can also be specified by using the COMArgument::NoValue enum. Note that this enum cannot be used when calling through the COMDispFunction class.

Examples

The following example shows how to call the COM.multiply method with the third argument unspecified.

Note

The code below contains a hypothetical COM object ("MyCOM.Object"), and will therefore not run in Microsoft Dynamics AX, unless such an object is created outside Microsoft Dynamics AX.

{ 
    COM        com; 
    COMVariant varArg1 = new COMVariant(); 
    COMVariant varArg2 = new COMVariant(); 
    COMVariant varArg3 = new COMVariant(); 
    COMVariant varRet  = new COMVariant(COMVariantInOut::OUT_RETVAL); 
    real       ret; 
    InteropPermission perm; 
  
    // Set code access permission to help protect use of COM object 
    perm = new InteropPermission(InteropKind::ComInterop); 
    if (perm == null) 
    { 
        return; 
    } 
  
    // Permission scope starts here 
    perm.assert(); 
  
    com = new COM("MyCOM.Object"); 
  
    // Specify arguments for the multiply method 
    varArg1.float(123); 
    varArg2.float(456); 
    varArg3.noValue(); 
    varRet = com.multiply(varArg1, varArg2, varArg3); 
    // …or… 
    varRet = com.multiply(varArg1, varArg2, COMArgument::NoValue); 
     ret = varRet.double(); 
    // ret is now 56088 (123*456) 
  
    // Close code access permission 
    CodeAccessPermission::revertAssert(); 
}

See Also

COMVariant Class

COM Class

COMDispFunction Class

COMDispFunction.call Method

COMVariant.new Method

COMVariant::createNoValue Method