Board index » delphi » breaking from loop when button pressed

breaking from loop when button pressed

Hello,
  Can anyone tell me how to break out of a repeat loop when a certain
button is pressed on the form.
Thanks.
 

Re:breaking from loop when button pressed


Quote
In article <36641796.8C07F...@swan.ac.uk>, 152672 wrote:
> Can anyone tell me how to break out of a repeat loop when a certain
> button is pressed on the form.

Try something like this:

var
  FButton1Clicked: Boolean;
..

in TForm1.FormCreate:
  FButton1Clicked := false; // paranoia <g>

in TForm1.Button1Click:
  FButton1Clicked := true;

in your loop:

while ...
begin
  // Do whatever you need

  // Give the app a chance to see a button click
  Application.ProcessMessages;
  if FButton1Clicked then
  begin
    FButton1Clicked := false; // Reset
    break; // leave the loop
  end;
end;

Hope this helps.

--
Tue, 01 Dec 1998 11:48 EST
Jim O'Brien, UnitOOPS Software
unito...@remove-this-prefix.unitoops.com
Check out our OLE Drag and Drop Components at http://www.unitoops.com/

Other Threads