Consultor Eletrônico



Kbase P4656: Dynamic widget triggers in internal procedures won't fire
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

SYMPTOM(s):

Dynamic widget triggers in internal procedures won't fire

CAUSE:

Triggers for dynamic widgets that have been created with an internal procedure will not fire unless they are persistent triggers.  The reason for this is trigger scope.  The scope of a non-persistent trigger created at run-time is the procedure, sub-procedure, or trigger block in which it is defined.

For example, the trigger for the dynamic button in the following code sample will not fire:


DEFINE VARIABLE num-btn AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE temp-hand AS HANDLE NO-UNDO.

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 DO:
       MESSAGE "You have selected the new button".
     END.
   END TRIGGERS.
END PROCEDURE.


FIX:

In order to have these triggers fire (triggers for dynamic widgets that have been created in internal procedures), those triggers will need to be persistent.  The trigger in the code sample above will fire with the following changes/additions:


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 "You have selected the new button".
END PROCEDURE.