Consultor Eletrônico



Kbase P13481: 4GL: how to create a button dynamically and assign a trigger
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   27/11/2003
Status: Verified

GOAL:

How to create a button dynamically and assign a trigger for it.

FIX:

Here there is a sample on how to do this:

DEFINE VAR num-btn AS INTEGER INIT 0.
DEFINE VAR temp-hand AS WIDGET-HANDLE.
DEFINE BUTTON make-btn LABEL "Make new button".

DEFINE FRAME btn-frame with width 44.
ENABLE make-btn WITH FRAME make-frame.

ON CHOOSE OF make-btn DO:
RUN make-proc.
END.

VIEW FRAME btn-frame.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.

PROCEDURE make-proc.
ASSIGN FRAME btn-frame:HEIGHT-CHARS = 10.

CREATE BUTTON temp-hand
ASSIGN
FRAME = FRAME btn-frame:HANDLE
ROW = 5
COLUMN = 10
LABEL = "New Button"
SENSITIVE = TRUE
VISIBLE = TRUE
TRIGGERS:
ON CHOOSE PERSISTENT RUN btn-mess IN THIS-PROCEDURE.
END TRIGGERS.
END PROCEDURE.

PROCEDURE btn-mess.
MESSAGE "Hello" SKIP "You have selected the new button"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.

Please note that it is always a good practice to use the IN THIS-PROCEDURE option in the trigger definition:

ON 'event' OF myHandle PERSISTENT RUN myProc IN THIS-PROCEDURE.

Without the IN THIS-PROCEDURE (or another procedure), the 'dynamic' trigger will not work if a WAIT-FOR was already active before creating the widget. In many cases, you may create dynamic widgets while a WAIT-FOR is already active, so this IN THIS-PROCEDURE is really required