Share via


COMVariant Class

The COMVariant class is used as a generic class that can store different types of data. The class is used to pass arguments to the methods or properties of a COM (Component Object Model) Automation object and is used with the COM and COMDispFunction classes.

Syntax

class COMVariant extends Object

Run On

Called

Methods

  Method Description
Gg836790.pubmethod(en-us,AX.60).gif boolean Gets or sets the value of a COMVariant object of the VT_BOOL data type.
Gg836790.pubmethod(en-us,AX.60).gif bStr Gets or sets the value of a COMVariant object of the VT_BSTR data type.
Gg836790.pubmethod(en-us,AX.60).gif byte Gets or sets the value of a COMVariant object of the VT_UI1 data type.
Gg836790.pubmethod(en-us,AX.60).gif cancelTimeOut Cancels a previous method call to the setTimeOut method. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif char Gets or sets the value of a COMVariant object of the VT_I1 data type.
Gg836790.pubmethod(en-us,AX.60).gif container Gets or sets the value of a COMVariant object of the container data type.
Gg836790.pubmethod(en-us,AX.60).gif currency Gets or sets the value of a COMVariant object of the VT_CY data type.
Gg836790.pubmethod(en-us,AX.60).gif date Gets or sets the date part of the value of a COMVariant object of the VT_DATE data type.
Gg836790.pubmethod(en-us,AX.60).gif decimal Gets or sets the value of a COMVariant object of the VT_DECIMAL data type.
Gg836790.pubmethod(en-us,AX.60).gif double Gets or sets the value of a COMVariant object of the VT_R8 data type.
Gg836790.pubmethod(en-us,AX.60).gif equal Determines whether the specified object is equal to the current one. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif finalize Not implemented. You can override this method if you need to explicitly destruct an object.
Gg836790.pubmethod(en-us,AX.60).gif float Gets or sets the value of a COMVariant object of the VT_R4 data type.
Gg836790.pubmethod(en-us,AX.60).gif getTimeOutTimerHandle Returns the timer handle for the object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif handle Retrieves the handle of the class of the object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif iDispatch Gets or sets the value of a COMVariant object of the VT_DISPATCH data type.
Gg836790.pubmethod(en-us,AX.60).gif int Gets or sets the value of a COMVariant object of the VT_I4 data type.
Gg836790.pubmethod(en-us,AX.60).gif iUnknown Gets or sets the value of a COMVariant object of the VT_UNKNOWN (IUnknown) data type.
Gg836790.pubmethod(en-us,AX.60).gif long Gets or sets the value of a COMVariant object of the VT_I4 data type.
Gg836790.pubmethod(en-us,AX.60).gif longLong Gets or sets the value of a COMVariant object of the VT_I8 (longlong) data type.
Gg836790.pubmethod(en-us,AX.60).gif new Initializes a new instance of the Object class. (Overrides the new Method.)
Gg836790.pubmethod(en-us,AX.60).gif notify Releases the hold on an object that has called the wait method on this object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif notifyAll Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif noValue 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.
Gg836790.pubmethod(en-us,AX.60).gif objectOnServer Determines whether the object is on a server. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif owner Returns the instance that owns the object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif safeArray Gets or sets the value of a COMVariant object of the VT_SAFEARRAY data type.
Gg836790.pubmethod(en-us,AX.60).gif sCode Gets or sets the value of a COMVariant object of the VT_ERROR data type.
Gg836790.pubmethod(en-us,AX.60).gif setTimeOut Sets up the scheduled execution of a specified method. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif short Gets or sets the value of a COMVariant object of the VT_I2 (short) data type.
Gg836790.pubmethod(en-us,AX.60).gif time Gets or sets the time part of the value of a COMVariant object of the VT_DATE data type.
Gg836790.pubmethod(en-us,AX.60).gif toString Creates a string representation of a COMVariant object. This string representation includes the value and type of the object. (Overrides the toString Method.)
Gg836790.pubmethod(en-us,AX.60).gif uInt Gets or sets the value of a COMVariant object of the VT_UI4 data type.
Gg836790.pubmethod(en-us,AX.60).gif uLong Gets or sets the value of a COMVariant object of the VT_UI4 (unsigned long) data type.
Gg836790.pubmethod(en-us,AX.60).gif uLongLong Gets or sets the value of a COMVariant object of the VT_UI8 (unsigned longlong) data type.
Gg836790.pubmethod(en-us,AX.60).gif usageCount Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif uShort Gets or sets the value of a COMVariant object of the VT_UI2 data type.
Gg836790.pubmethod(en-us,AX.60).gif variant Gets or sets the value of a COMVariant object of the VT_VARIANT (variant) data type.
Gg836790.pubmethod(en-us,AX.60).gif variantInOutFlag Sets or returns the InOutFlag setting for a COMVariant object.
Gg836790.pubmethod(en-us,AX.60).gif variantType Queries a COMVariant object for its variant data type or changes the data type.
Gg836790.pubmethod(en-us,AX.60).gif wait Pauses a process. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif xml Returns an XML string that represents the current object. (Inherited from Object.)
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createDateFromYMD Creates a new COMVariant object and initializes it with a date value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromArray Creates a new COMVariant object and initializes it with an array in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromBoolean Creates a new COMVariant object and initializes it with a Boolean value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromCOM Creates a new COMVariant object and initializes it with a COM class in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromDate Creates a new COMVariant object and initializes it with a date value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromDateAndTime Creates a new COMVariant object and initializes it with a date and time in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromInt Creates a new COMVariant object and initializes it with an integer value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromInt64 Creates a new COMVariant object and initializes it with an int64 value (longLong or uLongLong) in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromReal Creates a new COMVariant object and initializes it with a real value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromStr Creates a new COMVariant object and initializes it with a string in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromTime Creates a new COMVariant object and initializes it with a time value in one operation.
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createFromUtcDateTime
Gg836790.pubmethod(en-us,AX.60).gif Gg836790.static(en-us,AX.60).gif ::createNoValue Creates a COMVariant object of the VT_ERROR variant type with no value.

Top

Remarks

The data type of the COMVariant object can be set by:

  • The new method

  • The variantType method

  • The createFrom… methods. For example, the createFromBoolean method creates a COMVariant object of type VT_BOOL (= Boolean).

  • The property methods. For example, if you set a new value by using the boolean property, and the object is not of type VT_BOOL (= Boolean), it will be changed to this type.

The value of the data type is set by one of the property methods. For example, the value of a COMVariant object of type VT_BOOL is set by the boolean method. The possible data types and the methods that set their values are listed in the Remarks section.

The data types that the COMVariant class supports are not X++ data types, but data types defined by the COM Automation standard.

The COMVariant class is based on the VARIANT structure found in the Win32 SDK. For more information see the Win32 SDK documentation.

The property methods of the COMVariant class map to the COMVariantType values in the following way:

boolean

VT_BOOL

bStr

VT_BSTR

String data type

byte

VT_UI1

char

VT_I1

currency

VT_CY

date, time

VT_DATE

Date/time data type; both properties must be set.

decimal

VT_DECIMAL

double

VT_R8

float

VT_R4

iDispatch

VT_DISPATCH

int, long

VT_I4

VT_I4 is used for both the int and the long data types

iUnknown

VT_UNKNOWN

sCode

VT_ERROR

The scode data type is a COM data type that is equivalent to the Win32 HRESULT data type.

short

VT_I2

uInt, uLong

VT_UI4

VT_UI4 is used for both the uInt and the uLong data types

uShort

VT_UI2

variant

VT_VARIANT

safeArray

VT_SAFEARRAY

Array data type

Examples

The following example instantiates a COM object that exposes a method called multiply which multiplies two floating point numbers passed in as COMVariant parameters.

{ 
    COM com; 
    COMVariant varArg1 = new COMVariant(); 
    COMVariant varArg2 = new COMVariant(); 
    COMVariant varRet; 
    real ret; 
    InteropPermission perm; 
  
    // Set code access permission to help protect the use  
    // of the 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); 
    varRet = com.multiply(varArg1, varArg2); 
  
    ret = varRet.double(); 
    // 'ret' is now 56088 (123*456) 
  
    // Close the code access permission scope. 
    CodeAccessPermission::revertAssert(); 
}

Inheritance Hierarchy

Object Class
  COMVariant Class

See Also

COM Class

COM::createFromVariant Method

COMDispFunction Class