Simple example
- Last Updated: January 17, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
The following sample procedure, ShowDateTime.p, is a simple ABL application that accesses .NET objects. It makes
use of some of the basic ABL features that support access to .NET objects, including an
OpenEdge .NET class and two from among a set of controls that can optionally be installed to
support the GUI for .NET.
|
When you run ShowDateTime.p, it creates
and displays a dialog box that shows the current date and time, as shown in the following
figure.

The following is a description of the ABL elements used to implement this procedure, numbered according to the numbered comments in the sample code:
- The USING statements specify .NET namespaces (similar to ABL packages)
in which some of the referenced .NET object types are defined. This allows you to
reference the object type by its unqualified class or interface name. The
FROM ASSEMBLYoption tells ABL to search .NET assemblies (rather than ABL packages on PROPATH) for the definitions of types defined in these namespaces.Note: While sometimes named alike, .NET namespaces and assemblies are not the same thing. Assemblies are the physical files that contain actual type definitions, while namespaces are logical groups of types. Types in the same namespace can be defined in different assemblies, and a single assembly can define types in different namespaces. - This code defines object reference variables for the classes used in the
procedure. The Progress.Windows.Form class is an OpenEdge .NET class that inherits from
the Microsoft
System.Windows.Forms.Formclass and provides a .NET form object that is designed for use in an ABL session. TheUltraButtonandUltraLabelclasses (from theInfragistics.Win.Miscnamespace) are two of the Ultra Controls from Infragistics® installed with this OpenEdge release. TheUltraButtonprovides a button similar to the MicrosoftSystem.Windows.Forms.Buttonclass and theUltraLabelprovides a fill-in for displaying data, similar to theSystem.Windows.Forms.Labelclass. - The NEW function (classes) instantiates these .NET classes just like an ABL user-defined class.
- To initialize the button object, the procedure assigns ABL data type
values to selected
UltraButtonclass properties. However, the data type of theDialogResultproperty is the .NETSystem.Windows.Forms.DialogResultenumeration. Thus, the procedure sets this property to theOKmember of theDialogResultenumeration class.Note: TheDialogResultproperty has the same name as its data type, which is theDialogResultenumeration type. Although the names are the same, they do refer to two different things. - To initialize the date/time field object, the procedure assigns ABL data
type values to selected
UltraLabelclass properties. It gets the current date and time from the staticNowproperty of theSystem.DateTimeclass.Note: You can also obtain a similar result more efficiently using the NOW ABL built-in function, which also includes the time zone. However, this example uses the .NET property to demonstrate access to the .NET feature. - To initialize the dialog box object, the procedure assigns ABL data type
values to selected Progress.Windows.Form class properties, which are inherited from
System.Windows.Forms.Form. It also adds theUltraLabelandUltraButtoncontrols to the form by invoking theAdd( )method on the formControlsproperty. This property has the .NET type,System.Windows.Forms.Control+ControlCollection, which is an inner class of theControlclass. Because theFormclass inheritsControl, the form object can use this property to contain a collection of controls that the form can display in its client area. - After the form is resized according to the control dimensions, the procedure repositions the controls to center them in the form client area.
- Once the dialog box object is initialized, the procedure blocks for
input using a .NET-specific form of the WAIT-FOR statement for input-blocking .NET
methods. The syntax for this
WAIT-FORstatement invokes the .NET form method,ShowDialog( ), which displays the dialog box as well as blocking for input. The statement then blocks until you click the OK button or press the ENTER key. This causes the button object to publish aClickevent, during which .NET automatically sets theDialogResultproperty of the form to the enumeration value (DialogResult:OK) of the button's ownDialogResultproperty. Anything that sets theDialogResultproperty on a form displayed as a dialog box automatically causes the dialog box to close and theShowDialog( )method to return that same value, which also terminates theWAIT-FORstatement. If ShowDateTime.p needed to check the method return value, the .NETWAIT-FORstatement syntax also provides an option (SET) that conveniently makes this return value available to the procedure. - .NET garbage collects objects in much the same way that OpenEdge
garbage collects ABL class instances. However, .NET dialog boxes can be closed in a way
that prevents them from being garbage collected in a timely manner. Therefore, to ensure
garbage collection of a .NET dialog box object and to avoid the application memory leaks
that it can create, you must call the .NET
Dispose( )method on the object when you no longer need it. Calling this method is unnecessary, however, for most other .NET objects.
The remaining chapters of this book describe all of the features shown here (and more) for working with .NET objects in an ABL session.
Progress.Windows.Form, see the reference entry for
this class in ABL Reference. For the Ultra Controls added to
the .NET form, see OpenEdge Ultra Controls for .NET.