BOX function
(Windows only; GUI for .NET only)Returns an object reference to a .NET System.Object that contains (boxes) a .NET mapping of an ABL value. At run time, this mapping depends on the kind of ABL value passed to the function. If you pass an ABL primitive value, the function returns a corresponding .NET mapped object type. If you pass an ABL array of .NET-compatible elements, the function returns a corresponding .NET array object type.
Syntax
ABL-expression
Specifies an expression that specifies one of the following .NET-compatible ABL data types:A .NET-compatible ABL array is an ABL array of one of the listed ABL primitive types or an ABL array of any supported .NET object type (a .NET object type not mapped as specified in Table 23).AS-data-type-expression
IfABL-expression
is an ABL primitive type, this is a character expression equal to a keyword (AS data type) that matches the explicit .NET mapped data type into which you want to box the specifiedABL-expression
. IfABL-expression
is an ABL primitive array, the character expression is an AS data type that specifies the explicit .NET mapped data type that the elements of the array should be converted to in the resulting .NET array object. This AS data type must correspond to one of the .NET types that maps appropriately to the ABL primitive type (or array element type) ofABL-expression
(see Table 24).If you do not specifyAS-data-type-expression
andABL-expression
is an ABL primitive (or primitive array), ABL boxesABL-expression
using the default matching .NET type that corresponds to the ABL primitive type (or array element type) ofABL-expression
.This option has no meaning whenABL-expression
is an ABL array of a supported .NET object type.ExampleThe following code creates a .NET DataTable with a single DataRow containing two columns. It then adds data to the row for the two columns. The Item indexed property used to access the columns has the data type System.Object. So, to add data to each column, you might have to use the BOX function to box the specified ABL value into an appropriate System.Object instance for the column. For example:
Notes
- For many direct assignments of a System.Object to an ABL primitive value or .NET-compatible ABL array, use of the BOX function is optional, because ABL automatically boxes the assigned ABL value into its default matching .NET object type. However, one such assignment for which you must use the BOX function is when you want to box an ABL primitive value (or primitive array) as a valid .NET mapped data type (or array of mapped types) other than the default match, for example, when boxing an ABL INTEGER (or INTEGER EXTENT) as a .NET System.Byte (or "System.Byte[]").
- If you pass a compatible ABL value or array to an INPUT parameter of a .NET method, ABL automatically boxes the ABL value into the matching .NET System.Object or array object. For an ABL primitive (or primitive array) value, this automatic boxing also allows you to explicitly specify the .NET data type mapping if you use the AS data type option on the ABL argument that you pass to the INPUT parameter (see the Parameter passing syntax reference entry). This automatic boxing does not occur for an ABL method, procedure, or user-defined function passing the same parameters. In this case, you can do an initial direct assignment or use the BOX function to explicitly do the necessary conversion.
See also
OpenEdge Release 10.2B
|