1

This is my issue: On triger of a START button i wan to execute one block. And it should stop executing when I press STOP button.

Eg on triger of start button:

REPEAT:
    message "hai".
END.

and when I press STOP button It should stop. What additional condition should I give to REPEAT block?Preferably I dont want to write the condition in STOP button Triger..Please give suggestion .

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
Bhavin Bhaskaran
  • 572
  • 5
  • 17
  • 41

3 Answers3

2

Progress is not multi-threaded.

So you have to carefully think through which bits of code need to execute in what context in order to fake it. (More carefully than my initial "it cannot be done" response.)

As "firhang" points out "PROCESS EVENTS" can be used to check for events queued and ready to be acted on.

So you could run your loop inside an event handler and have that event handler listen for additional events.

I believe that the following satisfies the original question and works in both GUI and Character clients:

define variable i as integer no-undo.

define variable bStop as logical no-undo.

define button butStart label "Start".
define button butStop  label "Stop".

form butStart butStop with frame but-frame row 1. 

on choose of butStop bStop = true.

on choose of butStart do:

  bStop = false.

  do while bStop = false:
    i = i + 1.
    process events.
    message i.
  end. 

  message "Paused".

end.

enable butStart butStop with frame but-frame.

pause 0 before-hide.

wait-for window-close of current-window.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
1

PROCESS EVENTS statement Processes all outstanding events without blocking for user input.

Syntax

PROCESS EVENTS

Example This procedure counts to 1,000 until you choose STOP:

r-proevs.p

DEFINE VARIABLE ix       AS INTEGER NO-UNDO. 
DEFINE VARIABLE stop-sel AS LOGICAL NO-UNDO. 
DEFINE BUTTON stop-it LABEL "STOP". 
DISPLAY stop-it. 
ON CHOOSE OF stop-it 
   stop-sel = TRUE. 
ENABLE stop-it. 
DO ix = 1 TO 1000:   
  DISPLAY ix VIEW-AS TEXT. 
  PROCESS EVENTS. 
  IF stop-sel THEN LEAVE.  
END. 

On each pass through the loop, the procedure displays the new value of ix and then checks whether any events are waiting to be processed. If no events have occurred, execution continues and the loop iterates. If the STOP button has been chosen, that event is processed changing the value of stop-sel. When execution continues, the program exits the loop.

If the loop does not contain the PROCESS EVENTS statement, the choose event never processes and the loop iterates until ix equals 1,000.

Notes The WAIT-FOR statement processes all pending events and blocks all other execution until a specified event occurs. The PROCESS EVENTS statement processes all pending events and immediately continues execution with the next statement. If there are any asynchronous requests for which PROCEDURE-COMPLETE events have been received but not yet processed, this statement processes these events as described for the WAIT-FOR statement. You cannot call the .NET method system.Windows.Forms.Application:DoEvent( ) in ABL. The PROCESS EVENTS statement performs the function of this method. .NET can raise exceptions in the context of an ABL session when this statement executes.

firhang
  • 244
  • 2
  • 11
  • this is working.. thanks but it will work upto 1000. so I just gave do: ix=1 to ix+1 : that was just to make it available for infinite times... thanks.. – Bhavin Bhaskaran Apr 19 '12 at 11:48
0
DEFINE VARIABLE bStop AS LOGICAL NO-UNDO.

DEFINE BUTTON butStop LABEL "Stop".

FORM butStop WITH FRAME but-frame ROW 1. 

ON CHOOSE OF butStop bStop = TRUE.

ENABLE butStop WITH FRAME but-frame.

REPEAT:
  PROCESS EVENTS.
  MESSAGE "hai".
  IF bStop THEN LEAVE.
END. 

MESSAGE "stoped".

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
firhang
  • 244
  • 2
  • 11
  • 1
    This code does not work. The repeat keeps on executing and the WAIT-FOR is never executed. Thus there is no opportunity for the ON CHOOSE to execute. – Tom Bascom Mar 29 '12 at 22:09
  • Have you tried it? You should reading something about PROCESS EVENTS command. ;) – firhang Apr 13 '12 at 20:54
  • It "works" if you run it from a GUI desktop because there is already a WAIT-FOR active. But it is not doing what you think it is doing. The WAIT-FOR in your code does not execute until after the "stoped" message. You can see this more clearly if you run the sample code from a character client rather than from a GUI client. – Tom Bascom Apr 14 '12 at 19:16
  • this example was not about wait-for but about repeat block and listening on trigger event. and that is working... what will make wait-for statement is in this example is not important. that's all. read please, what that question is and than rate the answer. thanks – firhang Apr 15 '12 at 17:40
  • 1
    ehm... when you check so perfectly the scripts... your "if bStop = true then leave." is unnecessary... it will be checked in every step from do while block. – firhang Apr 15 '12 at 17:46
  • Good catch on the extra LEAVE. – Tom Bascom Apr 16 '12 at 00:56
  • Yes, you made a valuable point about PROCESS EVENTS but, like it or not, your example 1) doesn't work except when run in a GUI session and 2) even when it does work it only covers part of the original question (the STOP button part). You also put a WAIT-FOR in your example that is not doing what you seemed to think it was doing and which anyone coming along to follow that example would be misled by. – Tom Bascom Apr 16 '12 at 01:02
  • As new to Progress I am not able to understand what you both discussing hope I will get back and read your discussion later to make sure that I am also getting it.. thanks for your replies.. – Bhavin Bhaskaran Apr 19 '12 at 11:54