UNBOX function

(Windows only; GUI for .NET only)

Unboxes a .NET System.Object or array object and returns a value of a corresponding ABL primitive or array type.

Syntax

UNBOX ( object-reference )
object-reference

Specifies an object reference to a boxed .NET primitive value (System.Object) or to a one-dimensional .NET array object. For a list of the .NET primitive types that a System.Object can box, see Table 4.

If object-reference points to a boxed .NET primitive value, the function returns a value of the ABL primitive type that implicitly maps to the boxed .NET type.

If object-reference points to a one-dimensional .NET array object, the function returns a copy of the elements contained by the .NET array as an ABL array. If these elements are .NET mapped object types, the returned ABL array contains elements of the corresponding ABL primitive type. Otherwise, the ABL array contains object reference elements of the actual object type contained by the input .NET array.

Example

The following code creates a .NET DataTable with a single DataRow containing two columns, an integer and a character string, and adds data to the two columns in that row. It then processes the data from the "CustNum" (System.Int32) column to get an indication if its value is even or odd and assigns the result to the ABL INTEGER variable iVal. The Item indexed property that is used to access the data has the data type System.Object. So, to use its value in an expression, you must use the UNBOX function to unbox the underlying .NET mapped data type of the System.Object value. In this case, the referenced System.Object represents a System.Int32 value:

USING System.Data.* FROM ASSEMBLY.

DEFINE VARIABLE dataTable1 AS DataTable.
DEFINE VARIABLE dcCustNum  AS DataColumn.
DEFINE VARIABLE dcName     AS DataColumn.
DEFINE VARIABLE row1       AS DataRow.
DEFINE VARIABLE iVal       AS INTEGER.

dataTable1 = NEW DataTable( INPUT "Customer" ).

/* Create columns for a dataTable */
dcCustNum = NEW DataColumn( INPUT "CustNum" ).
dcName    = NEW DataColumn( INPUT "Name" ).
dataTable1:COLUMNS:ADD( INPUT dcCustNum ).
dataTable1:COLUMNS:ADD( INPUT dcName ).

/* Create a new row */
row1 = dataTable1:NewRow( ).

/* Add data to row. */
row1:Item["CustNum"] = 5.
row1:Item["Name"]    = "Mr Jones".

/* Process a value from the row. Without UNBOX, this does not compile.*/
iVal = UNBOX( row1:Item["CustNum"] ) MODULO 2. /* 1 = an odd value */

Notes

See also

BOX function, Data types