Sample ABL-derived .NET modal dialog box
- Last Updated: January 17, 2024
- 5 minute read
- OpenEdge
- Version 12.8
- Documentation
UTCDialog is a sample ABL-derived modal dialog box class that allows you to select a time zone used to display the current time, displayed as in the following figure.

The dialog box displays two buttons, UTC or EST? and OK, and a label field displaying a message that indicates which time zone is selected, Eastern Standard Time (EST) or Coordinated Universal Time (UTC). When you click the UTC or EST? button, the label field toggles between one message and the other and sets a flag to indicate the selected time zone. When the you click OK, this closes the dialog box with a result that indicates the selected time zone.
The sample ABL-derived non-modal form class, UTCSelectForm, creates an instance of the UTCDialog class and displays its modal dialog box. This non-modal form class is
similar to the CurrentTimeForm class described in Sample ABL-derived .NET non-modal form, and displays as in the following figure.

In this case, the Close button of
CurrentTimeForm is replaced by a Select Zone button in UTCSelectForm. The non-modal form displays the current date and time with an
indication of the time zone (UTC or EST). When you click the Select Zone button, this launches the UTCDialog instance where you can select the time zone for the current time. When
you close the dialog box with a selection, the form now displays the time in the specified
time zone, along with the appropriate time zone indication.
CurrentTimeForm,
UTCSelectForm makes its non-modal form the main form of
the application. So, clicking the Close (X) button on the form implicitly invokes the Close( ) method on the form, which both closes the main form and terminates the
application.The UTCSelectForm class launches its
UTCDialog instance in an event handler for the Select Zone button (TZButton_Click). The following fragment of UTCSelectForm shows the TZButton_Click event
handler and its supporting code.
|
TZButton_Click creates the UTCDialog instance referenced by rDialog, and
immediately executes the WaitForDialog( ) method on it.
This method executes the WAIT-FOR statement to display and block on the dialog box, which is
parented to the main form (THIS-OBJECT), passed in as an
INPUT parameter. When the method returns, it also returns
the enumeration value of the DialogResult property on the
dialog box, passed out as an OUTPUT parameter (enResult). In the UTCDialog
instance, the value of the DialogResult property is set in
a Click event handler to indicate time zone selected in the
dialog box.
DialogResult property, the WaitForDialog( )
method could directly return a LOGICAL value for the
lUTCSelected data member, which is also set in UTCDialog. However, this example also demonstrates another
potential use for the DialogResult property in an
application, especially where more complex results might be returned and you want the
property to reflect a priority condition.After the dialog box closes, this method returns, and the event handler
tests enResult to determine what time zone has been
selected. It then sets a UTCSelectForm class flag (lUTCSelected) accordingly and returns the current date and time,
as a string, using the private GetTime( ) method. The
GetTime( ) method also tests this flag and creates the
date and time string from either the current date and time UTC or the current date and time
EST (five hours earlier) and appends the time zone indicator before returning the result.
The event handler concludes by setting the Text property of
the UltraLabel instance (rDateField), which displays the date and time for the parent form.
WaitForDialog( )
returns, Dispose( ) is called on rDialog to ensure that the ABL-derived .NET dialog box object is garbage
collected. For more information, see Block on modal dialog boxes.This is the initial section of code for the ABL UTCDialog class, where the class private data and public members are
defined.
|
The private data includes object references for the dialog box object and
its control objects, and also includes its own class flag (lUTCSelected) to indicate the selected time zone. The public members include the
WaitForDialog( ) method that displays and blocks on the
dialog box and the UTCDialog class constructor.
The WaitForDialog( ) executes the
WAIT-FOR statement calling the ShowDialog( ) instance
method for the dialog box. This method takes the INPUT
parameter (pForm) that references the parent form for the
dialog box, which in this case will be the non-modal form instantiated by UTCSelectForm. It also returns the value of ShowDialog( ) (which is the DialogResult property value on rDialog) as an
OUTPUT parameter (pResult) after the corresponding dialog box closes, thus allowing the caller to
evaluate the dialog box results.
The constructor also takes a parameter (pUTCSelected) so that the caller can control the initial time zone selection in
the dialog box. And as for any similar container class (see Sample ABL-derived .NET non-modal form), its constructor calls a private InitializeComponent( ) method to initialize the dialog box and its controls.
This is the beginning of the InitializeComponent( ) method for UTCDialog,
showing the initialization of its controls.
|
Notable initializations for this class include setting the initial label
text (labelTZ:Text) to display an indication of currently
selected time zone and subscribing event handlers to the Click events on the dialog box buttons that determine the latest time zone
selection. Ultimately, the current time zone selection is indicated by the lUTCSelected flag. The value of this flag is initially set from
the parameter passed to the UTCDialog class constructor
and is reset according to the results of the dialog box.
This is the conclusion of the InitializeComponent( ) method for UTCDialog,
showing the dialog box initialization.
|
The last several settings for the dialog box object (THIS-OBJECT) initialization show some typical properties set for
a dialog box. Note especially the StartPosition property
set to FormStartPosition:CenterParent. This centers the
dialog box over its parent form, which in this case will be the non-modal form created by
UTCSelectForm, whose object reference (pForm) is passed to the WaitForDialog( ) method.
This is the concluding section of UTCDialog code showing its PRIVATE event
handlers.
|
In the okButton_Click event handler,
when the OK button (buttonOK) is clicked, it sets the DialogResult
property of the dialog box (THIS-OBJECT) depending on the
current value of the class private flag (lUTCSelected),
which setting closes the dialog box.
In the tzButton_Click event handler,
when the UTC or EST? button (buttonTZ) is clicked, it toggles the current time zone setting
by reversing the value of the lUTCSelected flag and
setting the Text property of the Label control (labelTZ) to indicate the newly
selected time zone. Note that the label is resized and re-centered in the dialog box
according to its current Text property value and font.