Try OpenEdge Now
skip to main content
GUI for .NET Programming
Using .NET data types in ABL : Accessing and using .NET arrays : Array assignment
 

Array assignment

An array assignment occurs either when you assign one array to another using an assignment (=) statement or when you pass an array as a routine parameter. In general, the rules for array assignment are different for assignment between ABL arrays compared to assignment between .NET arrays. For more information on the rules for ABL array assignment, see the assignment (=) statement and data types reference entries in OpenEdge Development: ABL Reference, and also see the Web paper, ABL Data Types in OpenEdge Release 10. The rules for .NET array assignment follow the general object-oriented rules for assigning object references, where the target type must be the same type as or higher in the same class hierarchy than the source type. The same rules apply to the elements of .NET source and target arrays, with an exception for arrays containing value type elements. For .NET arrays that contain value type elements, the source and target arrays must contain elements of an identical value type, such as System.Drawing.Size or System.Int32. In all cases, assignments between .NET arrays are object reference assignments (no array elements copied), while assignments between ABL arrays are always deep copies, with all the elements copied from one array to the other.
In a mixed array assignment between ABL and .NET arrays, the target array type (ABL or .NET) dictates the basic assignment rules. However, any assignment that includes an ABL array as either the source or the target causes a deep copy of the source array to the target. In the case of a .NET target array, ABL also creates a new .NET array to hold the elements of the ABL source array. In addition, the behavior of the assignment can be further affected by the element types of the source and target arrays (see Array mapping: conversion between ABL arrays and .NET arrays).
ABL enforces a special restriction in assignments to a Progress.Lang.Object. You cannot assign any ABL array type to a Progress.Lang.Object, even if the ABL array contains .NET object elements. In general, because ABL arrays are not objects themselves and ABL supports no automatic boxing to Progress.Lang.Object, there is no way to assign an ABL array to this (or any) pure ABL object type.
The following two tables list some common examples of assignments between different source and target array types, where each table focuses on either ABL or .NET target types. The listed .NET type names are shown without quotes and assume the following USING statements:
USING System.Windows.Forms.*
USING System.Drawing.*
Also note that System.Drawing.Size and System.Drawing.Color are .NET value types.
The following table contains sample array assignments where the target is a given ABL array type and the source is a given .NET or ABL object type. The last column indicates the validity (compatibility) of the assignment (Valid or Invalid) and additional comments. For .NET source array types, assume that the number of elements is identical to the number of elements in the target ABL array type, unless the target ABL array has an indeterminate extent, in which case a compatible source array assignment fixes the extent of the target ABL array.
ABL target type
Source type
Validity — Comments
System.Object EXTENT
Control[]
Valid — Class type elements assigned to super class elements
System.Object EXTENT
System.Boolean[]
Invalid — ABL rules: boxing not supported on array elements during array conversion
Progress.Lang.Object EXTENT
System.Int32[]
Invalid — ABL rules: no boxing supported for Progress.Lang.Object elements
Progress.Lang.Object EXTENT
Button[]
Valid — ABL rules: .NET class type elements assigned to ABL root class elements
Progress.Lang.Object EXTENT
Size[]
Valid — ABL rules: .NET value type (Size) treated just like any class type assigned to ABL root class elements
Size EXTENT
Size[]
Valid — Elements of same object type assigned to each other
Control EXTENT
Button[]
Valid — Class type elements assigned to super class elements
Button EXTENT
Control[]
Invalid — Attempt to assign class type elements to subclass elements
INTEGER EXTENT
System.Object
Invalid — ABL rules: automatic unboxing and conversion from a System.Object to an ABL array not supported, even if the .NET root class object reference represents a compatible .NET array object
INTEGER EXTENT
System.Array
Invalid — ABL rules: automatic unboxing and conversion from a System.Array to an ABL array not supported, even if the base class reference for .NET arrays represents a compatible .NET array object
INTEGER EXTENT
Progress.Lang.Object
Invalid — ABL rules: automatic unboxing and conversion from a Progress.Lang.Object to an ABL array not supported, even if the ABL root class object reference represents a compatible .NET array object
INTEGER EXTENT
System.Int16[]
Valid — ABL mapping between an ABL primitive array and a compatible .NET array of mapped types
CHARACTER EXTENT
System.Int32[]
Valid — ABL rules: For procedure parameters only, ABL weakly typed mapping supported between source and target ABL array types (converted from .NET source)
Invalid — Incompatible mapping between ABL primitive and .NET arrays of mapped types for direct assignment or .NET method and ABL user-defined function parameter passing
The following table contains sample array assignments where the target is a given .NET or ABL object type and the source is another ABL or .NET type. The last column indicates the validity (compatibility) of the assignment (Valid or Invalid) and any additional comments. Note that when assigning to a .NET array, the number of elements in source and target arrays can be different, because the target is always assigned an object reference that points to the source array, whatever its extent.
.NET object or ABL root class target type
Source type
Validity — Comments
System.Object
Button EXTENT
Valid — .NET rules: ABL maps the source to a Button[] array that .NET assigns to the super class object reference
System.Object
CHARACTER EXTENT
Valid — ABL rules: For direct assignments and passing parameters to .NET methods and constructors, ABL boxes a System.String[] in a System.Object and assigns it to the target System.Object object referenceInvalid — For passing parameters to ABL routines, boxing to a System.Object not supported
System.Object
MyABLClass EXTENT
Invalid — .NET and ABL rules: Cannot map an ABL array of ABL objects to an array object that .NET can assign
System.Array
Button EXTENT
Valid — .NET rules: ABL maps the source to a Button[] array that .NET assigns to the super class object reference
System.Array
Color EXTENT
Valid — .NET rules: ABL maps the source to a Color[] value type array that .NET assigns to the super class object reference
System.Array
INTEGER EXTENT
Valid — .NET rules: ABL maps the source to a System.Int32[] array that .NET assigns to the super class object reference
System.Array
Progress.Lang.Object EXTENT
Invalid — .NET and ABL rules: Cannot map an ABL array of ABL objects to an array object that .NET can assign
Progress.Lang.Object
Control EXTENT
Invalid — ABL rules: Cannot assign an ABL array of any type to a Progress.Lang.Object object reference
Progress.Lang.Object
Button[]
Valid — .NET and ABL rules: Assigns the .NET array object to the super class object reference
Progress.Lang.Object
INTEGER EXTENT
Invalid — ABL rules: Cannot box an ABL primitive array in a Progress.Lang.Object
Progress.Lang.Object
Progress.Lang.Object EXTENT
Invalid — ABL rules: Cannot assign an ABL array of any type to a Progress.Lang.Object object reference
System.Object[]
Form EXTENT
Valid — .NET rules: ABL maps the source to a Form[] array that .NET assigns to the super class object reference of a .NET array of super class reference type elements
System.Object[]
Size EXTENT
Invalid — .NET rules: ABL maps the source to a Size[] array object, but .NET can only assign an array of value type elements to an array reference of identical value type elements
System.Object[]
MyABLClass EXTENT
Invalid — .NET and ABL rules: Cannot map an ABL array of ABL objects to an array object that .NET can assign
System.Object[]
DECIMAL EXTENT
Invalid — .NET rules: ABL maps the source to a System.Decimal[] array, but .NET can only assign an array of value type elements to an array reference of identical value type elements
Control[]
TextBox EXTENT
Valid — .NET rules: ABL maps the source to a TextBox[] array that .NET assigns to the super class object reference of a .NET array of super class reference type elements
Button[]
Button EXTENT
Valid — .NET rules: ABL maps the source to a Button[] array that .NET assigns to the object reference of an identical array type
Button[]
Control EXTENT
Invalid — .NET rules: ABL maps the source to a Constrol[] array, but .NET cannot assign an array of object types to an array of subclass object types
Size[]
Size EXTENT
Valid — .NET rules: ABL maps the source to a Size[] array that .NET assigns to an array reference of identical value type elements
System.Int32[]
INTEGER EXTENT
Valid — .NET rules: ABL maps the source to an implicitly matching System.Int32[] array that .NET assigns to an array reference of identical value type elements
System.Int16[]
INTEGER EXTENT
Valid — .NET rules: ABL maps the source to an implicitly matching System.Int16[] array that .NET assigns to an array reference of identical value type elements
System.Decimal[]
INTEGER EXTENT
Invalid — .NET rules: ABL cannot map the source to an implicitly matching .NET array type where the value type (System.Decimal) of the source and target array elements match
System.DateTime[]
DATE EXTENT
Valid — .NET rules: ABL maps the source to an implicitly matching System.DateTime[] array that .NET assigns to an array reference of identical value type elements
System.String[]
LONGCHAR EXTENT
Valid — .NET rules: ABL maps the source to an implicitly matching System.String[] array that .NET assigns to the object reference of an identical array type