Board index » delphi » Interrupting long loop

Interrupting long loop

Hi everyone.

How can I interrupt a loop in the following situation (D1):

Form X has a start and stop button
The start button calls a procedure UpdateDatabase() in unit Y, which
takes a long time. This contains a loop

  WHILE (Not end-of-table) and (not AbortFlag)
    ....
    Application.ProcessMessages;
  END

Form Y is never shown.

Unit Y Show()s a form Z which has only a TGauge to show the progress,
and updates this continously with AddGauge.

The stop button on form X sets AbortFlag to TRUE, then calls Close().
All forms are autoCreated.

Problems:
- I cannot interrupt the loop. The ProgressBar form keeps having the focus
- When the loop is complete, form X does not regain focus, I have to
  reset the program through the Delphi menu.

Bye,
Jan

-----------------------------------------------------------------------
Jan Doggen                Masters Software           mass...@xs4all.nl
P.O. Box 697              2300 RA  Leiden            The Netherlands
-----------------------------------------------------------------------
** Specialists in multimedia software for education and presentation **
-----------------------------------------------------------------------
Usage of this email address for commercial purposes costs US$ 50 per
message. By using this email address you agree to this condition.
-----------------------------------------------------------------------

 

Re:Interrupting long loop


Option 1: put the button that sets the Abort flag on form Z with the progress
bar
Option 2: Don't continuously update the progress bar.  Set some reasonable
intervals - say 10 or 20 percent of the task, and do the updates of the
progress bar only when it hits those magic numbers.
hth
/js

In article <6eokbm$8b...@news2.xs4all.nl>, mass...@xs4all.nl (Jan Doggen)
writes:

Quote
>Hi everyone.

>How can I interrupt a loop in the following situation (D1):

>Form X has a start and stop button
>The start button calls a procedure UpdateDatabase() in unit Y, which
>takes a long time. This contains a loop

>  WHILE (Not end-of-table) and (not AbortFlag)
>    ....
>    Application.ProcessMessages;
>  END

>Form Y is never shown.

>Unit Y Show()s a form Z which has only a TGauge to show the progress,
>and updates this continously with AddGauge.

>The stop button on form X sets AbortFlag to TRUE, then calls Close().
>All forms are autoCreated.

>Problems:
>- I cannot interrupt the loop. The ProgressBar form keeps having the focus
>- When the loop is complete, form X does not regain focus, I have to
>  reset the program through the Delphi menu.

>Bye,
>Jan

Other Threads