Kbase P187004: PROCESS EVENTS statement loses user input
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  03/05/2011 |
|
Status: Unverified
SYMPTOM(s):
PROCESS EVENTS statement loses user input
User input is lost when using PROCESS EVENTS in a loop
If data is entered while the loop in the following code is runnig, then it is lost and not displayed in the variable at the end of the program.
DEFINE VARIABLE v_cnt AS INTEGER NO-UNDO.
REPEAT v_cnt = 1 TO 20000:
DISPLAY v_cnt WITH 1 DOWN.
PAUSE 0.
IF v_cnt MODULO 1000 = 0 THEN
PROCESS EVENTS.
END.
DEFINE VARIABLE cmyinput AS CHARACTER.
UPDATE cmyinput.
Comment out the PROCESS EVENTS IF statement and the entered data is preserved.
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
CAUSE:
This is expected behavior. The keystrokes are held in the AVM process's message queue until they are retrieved. PROCESS EVENTS makes the AVM retrieve messages from the queue.
FIX:
When the PROCESS EVENTS IF statement is removed from the code, the AVM does not retrieve any of the keystroke messages while the loop is executing. When the loop is over, the cmyinput fill-in is displayed and the AVM starts retrieving messages because the UPDATE statement blocks for input. The queued messages are retrieved and the characters appear in the fill-in.
If the code runs with the PROCESS EVENTS IF statement, the AVM retrieves the messages while the loop is executing. Since there isn't a widget with input focus, the characters have nowhere to go and they are dropped (actually, they go to the frame but it doesn't have any use for them since frames don't accept input).
The following version of the program collects the input by enabling the fill-in before entering the loop.
DEFINE VARIABLE cmyinput AS CHARACTER.
DEFINE VARIABLE v_cnt AS INTEGER NO-UNDO.
ENABLE cmyinput.
APPLY "entry" TO cmyinput.
REPEAT v_cnt = 1 TO 20000:
DISPLAY v_cnt WITH 1 DOWN.
PAUSE 0.
IF v_cnt MODULO 1000 = 0 THEN
PROCESS EVENTS.
END.
UPDATE cmyinput.