COMVariant.variant Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
variant() |
Gets or sets the value of a COMVariant object of the VT_VARIANT (variant) data type. |
variant(COMVariant) |
variant()
Gets or sets the value of a COMVariant object of the VT_VARIANT (variant) data type.
public:
virtual Dynamics::AX::Application::COMVariant ^ variant();
public virtual Dynamics.AX.Application.COMVariant variant ();
abstract member variant : unit -> Dynamics.AX.Application.COMVariant
override this.variant : unit -> Dynamics.AX.Application.COMVariant
Public Overridable Function variant () As COMVariant
Returns
The current value.
Remarks
The variant property is used to nest one COMVariant object in another COMVariant object. When using the parent object as the argument in a call to COMDispFunction.call or in a call to the COM class, the called method will automatically extract the data of the nested object. This nesting facility is useful when a method on a COM object can work with multiple data types. Only one level of variant nesting is allowed. If you pass in a value that has a different data type than the object, the data type of the object will be changed to match the data type of the value. A COMVariant object has a variant type if its data type is set to COMVariantType::VT_VARIANT.
The following example creates a COMVariant object of type VT_I4 (long), and a COMVariant object of type VT_VARIANT. The object of type VT_VARIANT is assigned the value of the object of type VT_I4. The code below contains a hypothetical COM object ("MyCOM.Object"), and will therefore not run in Finance and Operations, unless such an object is created outside Finance and Operations.
{
COM com;
COMDispFunction funcShow;
COMVariant var1 = new COMVariant(
COMVariantInOut::IN_OUT,
COMVariantType::VT_I4);
COMVariant var2 = new COMVariant(
COMVariantInOut::IN_OUT,
COMVariantType::VT_VARIANT);
InteropPermission perm1;
InteropPermission perm2;
// Set code access permission to help protect use of COM object
perm1 = new InteropPermission(InteropKind::ComInterop);
perm1.assert();
com = new COM("MyCOM.Object");
// Close code access permission for COM
CodeAccessPermission::revertAssert();
// Set value of 'var1'
var1.Long(123456);
// Set value of 'var2' to 'var1'
var2.Variant(var1);
// Set code access permission to protect use of
// COMDispFunction object
perm2 = new InteropPermission(InteropKind::ComInterop);
perm2.assert();
funcShow = new COMDispFunction(
com,
"Show",
COMDispContext::METHOD);
// Call funcShow with a long
funcShow.Call(var2);
// Change value of 'var1'
var1.BStr("Hello World");
// Call funcShow with a string
funcShow.Call(var2);
// Close code access permission for COMDispFunction
CodeAccessPermission::revertAssert();
}
Applies to
variant(COMVariant)
public:
virtual Dynamics::AX::Application::COMVariant ^ variant(Dynamics::AX::Application::COMVariant ^ _newValue);
public virtual Dynamics.AX.Application.COMVariant variant (Dynamics.AX.Application.COMVariant _newValue);
abstract member variant : Dynamics.AX.Application.COMVariant -> Dynamics.AX.Application.COMVariant
override this.variant : Dynamics.AX.Application.COMVariant -> Dynamics.AX.Application.COMVariant
Public Overridable Function variant (_newValue As COMVariant) As COMVariant
Parameters
- _newValue
- COMVariant
The new value; optional.