Consultor Eletrônico



Kbase P14889: How to implement a timer without an OCX
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/05/2011
Status: Verified

GOAL:

How to implement a timer without an OCX.

GOAL:

How to implement a timer portable across Windows and UNIX.

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x
All Supported Operating Systems

FIX:

The idea is to have a window with one fill-in widget to serve as the clock. It is advisable to make this fill-in VIEW-AS TEXT (by making sure it is displayed but not enabled for user input.)

One other feature is a logical variable called GET-OUT which serves as a way for the program to get out of the timer loop and exit the program. Define it as follows, with initial value FALSE:

DEFINE VARIABLE get-out AS LOGICAL INITIAL FALSE.

To implement the timer, write a loop around the WAIT-FOR that is similar to the following:

DO WHILE TRUE:
fill-in-1:SCREEN-VALUE = STRING(TIME, "HH:MM:SS").
WAIT-FOR U1 OF CURRENT-WINDOW PAUSE 1.
IF get-out THEN LEAVE.
END.

The way to "break out" of the loop is to set get-out to be true.
One event to take into account with this is WINDOW-CLOSE, since as it stands the WAIT-FOR above is waiting for a "dummy" programmer event, U1, and not the usual WINDOW-CLOSE. So, in order to assure that WINDOW-CLOSE will work properly, you need to make sure a trigger is defined for the WINDOW-CLOSE event:

ON WINDOW-CLOSE OF WINDOW-1 DO:
get-out = TRUE.
RETURN NO-APPLY.
END.

The RETURN NO-APPLY assures that a beep won't occur when the user closes the window using a ventilator.

One other way that the logical variable get-out could be set is as the result of an "Exit" button:

ON "CHOOSE" OF btn_exit DO:
get-out = TRUE.
END.

Other events can set get-out = TRUE as desired.