Board index » delphi » While-loop interrupted by Click on Button?

While-loop interrupted by Click on Button?

-- I have following problem concerning Delphi:

A while-loop should be interrupted by a Click event
on a Button. A MessageBox or something like that should
occur, and after a further mouse click (on an O.K. Button)
the loop should continue working.

I tried this but the (first) button click has an effect
only after the loop has already finished. This is not
useful, of course.

Does anyone know a solution for this problem?

Peter (hop...@uni-muenster.de)

 

Re:While-loop interrupted by Click on Button?


You have to allow the windoze message generated by
the button click to be 'processed'. You can do that
by inserting the call to Application.ProcessMessages
in your while stmt.

--
Grace + Peace | Peter N Roth | Engineering Objects Int'l
  Author: Round Robin, a Delphi scheduling component
Visit our website at http://www.inconresearch.com/eoi
"Random numbers are too important to be left to chance." - anon

Re:While-loop interrupted by Click on Button?


You must put a flag private for the form, and check it inside the loop if
it is false or true. In the button, you set the flag to true (ex.).

But the good part is here, Inside the loop you must put the following
command:

Application.ProcessMessages;

This will process messages that Windows sends to the form, like a mouse
click, get it? Without this, the form will wait the process to process the
Windows messages.

Romulo Nobrega (alma@elogica~com.br)  --->> Replace ~ with .

Peter Hoppe <hop...@uni-muenster.de> escreveu no artigo
<34FB400F.2...@uni-muenster.de>...

Quote
> -- I have following problem concerning Delphi:

> A while-loop should be interrupted by a Click event
> on a Button. A MessageBox or something like that should
> occur, and after a further mouse click (on an O.K. Button)
> the loop should continue working.

> Peter (hop...@uni-muenster.de)

Re:While-loop interrupted by Click on Button?


In article <34FB400F.2...@uni-muenster.de>, someone calling themselves

Quote
"Peter Hoppe" <hop...@uni-muenster.de> wrote:
>-- I have following problem concerning Delphi:

>A while-loop should be interrupted by a Click event
>on a Button. A MessageBox or something like that should
>occur, and after a further mouse click (on an O.K. Button)
>the loop should continue working.

>I tried this but the (first) button click has an effect
>only after the loop has already finished. This is not
>useful, of course.

>Does anyone know a solution for this problem?

I put a variable in the form class like this:

private
   Done: Boolean;

then initialise it to False in the FormCreate method. Then, when the
Cancel button is clicked, do this:

procedure TForm1.CancelBtnClick(Sender: TObject);
begin
   Done := True;
end;

and put a reference to "Done" and an Application.ProcessMessages in
your while loop, like this:

{ for example... }
while not Eof and not Done do
begin
   Application.ProcessMessages;
   DoMyStuff()
   Table1.Next;
end;

Hope this helps.

|~\  /~| /~~| |~|   The .sig wears a ring of polymorph! --More--
|  \/  |/ / |_| |__ The .login hits! The .cshrc bites!
|      ' /| |_| | / ________________________________________________
| |\/|  /\  | |  /  Official member of STI:
| |  |_/  \_| | /           The Search for Terrestrial Intelligence!
=\|===========|/==========- The Mabster:  mhamil...@bunge.com.au -==

Re:While-loop interrupted by Click on Button?


Try using a global variable (such as Cancelled)...  In your button event set
Cancelled:=True;  In your loop:

  repeat
      {your code here}
      Application.ProcessMessages;
  until not Cancelled;

Doug Johnson (d...@homemail.com)

Quote
Peter Hoppe wrote in message <34FB400F.2...@uni-muenster.de>...
>-- I have following problem concerning Delphi:

>A while-loop should be interrupted by a Click event
>on a Button. A MessageBox or something like that should
>occur, and after a further mouse click (on an O.K. Button)
>the loop should continue working.

>I tried this but the (first) button click has an effect
>only after the loop has already finished. This is not
>useful, of course.

>Does anyone know a solution for this problem?

>Peter (hop...@uni-muenster.de)

Other Threads