Example: Access a .NET array
- Last Updated: July 25, 2024
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
This topic first introduces the use of .NET array objects in ABL with the
EventHandlers.p example described in Access .NET Objects to demonstrate .NET event handling (see Event handling example).
The following procedure, PointArray.p, is a simpler version of the same
application, which handles fewer .NET events, in order to focus on array handling, in this
case, using an array of System.Drawing.Point objects used to draw a regular
octagon in a graphic region, as shown in the following figure.

From a calculation based on the dimensions of the current client area in a
.NET form, the Point objects of the array specify vertices
between the sides of the octagon (determined by an AdjustOctagon( ) user-defined function). This procedure then calculates and
re-displays the octagon from the point array each time you click the Draw button.
The procedure begins by defining a System.Array object as a point array, a single Point object used to set elements of this array, and the basic user interface
elements to display the octagon. In particular, the bold code shows the definition and
instantiation of the point array object with the eight points required to draw an octagon.
This code instantiates a new Point object and instantiates
the array object by calling NEW with the element type
parameter value obtained using the Point object instance
just created. Note that System.Drawing.Point is a value
type (structure). So, .NET instantiates the array with default (0-valued) Point objects stored in each element.
|
Infragistics.Win.Misc.UltraButton class is one of the
OpenEdge Ultra Controls for .NET provided with OpenEdge, and
Progress.Windows.Form is an OpenEdge extension of
System.Windows.Forms.Form designed specifically for running in the ABL
environment. For more information on these objects, see Create and use forms and controls.
PointArray.p continues with the following code to initialize the user
interface elements and graphical constants used to build and display octagons. To create a
.NET form, the procedure uses the OpenEdge .NET class, Progress.Windows.Form, which, as
previously noted, is derived from the System.Windows.Forms.Form class.
|
To actually draw the octagon, the example subscribes an internal procedure,
Draw, as a handler for the Click event on the form
button. Thus, when you click the button referenced by rDrawBtn, the
procedure updates the octagon point coordinates and draws it in the form. For more
information on handling .NET events, see Handle .NET events.
The Draw event handler procedure that follows responds to the button
Click event by drawing the octagon from the point array returned by the
AdjustOctagon user-defined function. It is the
DrawPolygon( ) method that requires that the array object be passed as a
"System.Drawing.Point[]" object rather than as the
System.Array super class object initially created.
System.Drawing.Common assembly be noted in
assemblies.xml; it is not automatically available as it is with .NET
Framework.
|
PointArray.p procedure also demonstrates the technique
for drawing graphics using the graphics object (rGraphics) that is
associated with a .NET form. You can only draw form graphics in a form event handler,
because the associated graphics object is available for drawing only during the handling of
a form event.As noted previously, the AdjustOctagon user-defined function determines
all the points of the array required to draw an octagon within the current client area of
the form. This, then, is where ABL uses the single System.Drawing.Point
object (rPoint) to set each element of the array using a 0-based index
(idx).
|
ABL can use this single System.Drawing.Point object to set each array
element, because, as a value type, .NET maintains its own copies of all the
Point objects stored in the array. ABL can then reset the members of all
the array element objects from a single modified object that ABL passes to the
SetValue( ) method. After all the Point objects have
been set, the function returns the updated point array as a value for use in the
Draw event handler (previously described).
The following CalcOctagonSide internal procedure uses a formula based on
the square root of 2 to calculate the horizontal or vertical components used to derive
coordinates for each point of the octagon.
|