UNBOX function
- Last Updated: July 20, 2021
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
(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
|
- 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 aSystem.Objectcan box, see Data types.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:
|
Notes
- You
must use the UNBOX function if you want to reference an appropriate
System.Objectproperty or method return value in an ABL primitive expression, such as when performing arithmetic operations together with compatible ABL variables, fields, or literal values. Invoke the UNBOX function directly in the expression, passing it theSystem.Objectas input, where you would otherwise reference theSystem.Objectitself. - For any direct assignment of a .NET object or object array to a compatible ABL primitive value or array, use of the UNBOX function is optional, because ABL automatically unboxes the underlying .NET object or array object type to its matching ABL primitive or array type.
- If you have a variable or field defined as a compatible ABL array type that you provide as an argument to an OUTPUT parameter of a .NET method defined as a .NET array object, ABL automatically unboxes the .NET array object into the ABL array argument. This automatic unboxing does not occur for an ABL method, procedure, or user-defined function passing the same parameters. In this case, you can use a direct assignment from a compatible .NET array object argument or use the UNBOX function to explicitly do the necessary conversion.