A class definition file can use all static widgets (for example, BROWSE, BUTTON, FRAME, IMAGE, MENU, RECTANGLE, SUB-MENU), as well as certain other static handle-based objects, including STREAM and WORK-TABLE objects. However, you can only define these handle-based objects as data members that are local to a class definition file, that is, as PRIVATE data members.
Also, because a class definition file does not support executable code in the main block, neither the WAIT-FOR statement nor conditional code is supported within the main block of a class definition file. The main block can only contain the CLASS statement, DEFINE statements, and ON statements. Typical graphical user interface (GUI) applications have a WAIT-FOR statement or include ON statements within conditional execution pathways.
Therefore, when using GUI objects you must follow these restrictions:
1. An ON statement cannot have any conditional code surrounding its definition.
2. The WAIT-FOR statement can only be specified in a method or constructor.
3. All GUI objects must be implicitly or explicitly defined as PRIVATE.
Given these rules, the following class definition file is valid:
CLASS Driver:
DEFINE PRIVATE BUTTON msg.
DEFINE PRIVATE BUTTON done.
DEFINE FRAME f msg done.
ON 'choose':U OF msg IN FRAME f DO:
MESSAGE "click" VIEW-AS ALERT-BOX.
END.
CONSTRUCTOR PUBLIC Driver ( ):
ModalDisplay ( ).
END CONSTRUCTOR.
METHOD PRIVATE VOID ModalDisplay ( ):
ENABLE ALL WITH FRAME f.
WAIT-FOR CHOOSE OF done.
END METHOD.
END CLASS.
However, the following class definition file is invalid, because the lines marked with bold-faced comments (#1 and #2) contain executable code:
CLASS Driver:
DEFINE VARIABLE bGraphical AS LOGICAL NO-UNDO.
DEFINE PRIVATE BUTTON msg.
DEFINE PRIVATE BUTTON done.
DEFINE FRAME f msg done.
/* #1 */ IF bGraphical THEN DO:
ON 'choose':U OF msg IN FRAME f DO:
MESSAGE "click" VIEW-AS ALERT-BOX.
END.
END.
ELSE DO:
ON 'choose':U OF msg IN FRAME f DO:
PUT "click" TO STREAM outstream.
END.
END.
CONSTRUCTOR PUBLIC Driver ( ):
ModalDisplay ( ).
END CONSTRUCTOR.
METHOD PRIVATE VOID ModalDisplay ( ):
ENABLE ALL WITH FRAME f.
END METHOD.