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