Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Gets or sets the value of a COMVariant object of the container data type.
Syntax
public container container([container newValue, COMVariantType newType])
Run On
Called
Parameters
- newValue
Type: container
The new container; optional.
- newType
Type: COMVariantType Enumeration
The type of the new container; optional. The default is for the container to store integers.
Return Value
Type: container
The current container.
Remarks
The possible values for the newType parameter are a subset of the values that are supplied by the COMVariantType system enum:
VT_I2
VT_I4
VT_R4
VT_R8
VT_CY
VT_DATE
VT_BSTR
VT_ERROR
VT_BOOL
VT_DECIMAL
VT_I1
VT_UI1
VT_UI2
VT_UI4
VT_I8
VT_UI8
VT_INT
VT_UINT
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.
When a container is stored in a COMVariant object, the binary representation of the container is stored in a binary array (see the COMVariant.safeArray method). The container property is useful when you need to store data in a database COM object and then later read the data back into Microsoft Dynamics AX without the COM object processing the data.
The container property is an advanced property of the COMVariant class. It should be used with caution because the content of the binary array that the container is stored in, inside the COMVariant object, must not be changed by any COM object.
Examples
The following example creates a new COMVariant object of type container. The data in the container is passed to, and used by, a database COM object.
Note
The code in the following section contains a hypothetical COM object ("MyDatabaseCOM.Object") and will therefore not run in Microsoft Dynamics AX, unless such an object is created outside Microsoft Dynamics AX.
{
COM com;
COMVariant var = new COMVariant();
container con;
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();
// Put some data in the container
con = conins(con, 1, "Element 1");
con = conins(con, 2, "Element 2");
// Set value of the object and ensure the data
// is stored in a binary array of bytes
var.container(con, COMVariantType::VT_UI1);
// Create a database object to store the data in
com = new COM("MyDatabaseCOM.Object");
com.writeData(var);
// ...
// Close code access permission
CodeAccessPermission::revertAssert();
}