PreviousNextIndex

UNBOX function


(Windows only; GUI for .NET only)

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

Syntax

UNBOX ( object-reference ) 

object-reference
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


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex