Board index » cppbuilder » huh? loops??

huh? loops??

Hi, newbie question: a form with 2 buttons, the first starts a loop, the
second should stop it. How do I get to interrupt the loop by clicking on
the second button? (I ordered a book on builder but it hasn't arrived
yet!).

help would be greatly appriciated!

victor

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   for(int i = 0; i<1000; i++)
   {
       StatusBar1->SimpleText = "numer "+IntToStr(i);
       if (Button2->OnClick)                            //<= this is
always true?
          StatusBar1->SimpleText = "yep";
   }

Quote
}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
// this function is not visible during the loop ????
         StatusBar1->SimpleText = "huh?";

Quote
}

 

Re:huh? loops??


In order to get Windows to respond to loops, the loop must execute
Application->ProcessMessages()
Use a global variable to control the loop.

Bimo

Quote
Victor Jetten wrote in message <36B316EF.AC02...@geog.uu.nl>...
>Hi, newbie question: a form with 2 buttons, the first starts a loop, the
>second should stop it. How do I get to interrupt the loop by clicking on
>the second button? (I ordered a book on builder but it hasn't arrived
>yet!).

>help would be greatly appriciated!

>victor

>//-------------------------------------------------------------------------
--

>void __fastcall TForm1::Button1Click(TObject *Sender)
>{
>   for(int i = 0; i<1000; i++)
>   {
>       StatusBar1->SimpleText = "numer "+IntToStr(i);
>       if (Button2->OnClick)                            //<= this is
>always true?
>          StatusBar1->SimpleText = "yep";
>   }
>}
>//-------------------------------------------------------------------------
--

>void __fastcall TForm1::Button2Click(TObject *Sender)
>{
>// this function is not visible during the loop ????
>         StatusBar1->SimpleText = "huh?";
>}

Other Threads