Re: Simple question

Posted by Tony on February 18, 2009

In Reply to Re: Simple question posted by Jimmy Lee on January 07, 2009

: : Label1.Caption := '1';
: : Sleep(1000); // 1 second
: : Label1.Caption := '2';
: : Sleep(1000);
: : Label1.Caption := '3';
: : Sleep(1000);
: : I expect to see the caption counting up in increments of one second but what it actually does is the label does not change untill the whole process is finished, in this case in 3 seconds the label will display 3, I never see the 1 or 2. How can I get round this please?

: Tip: if you want a response, better give your post a meaningful subject :-p
: Not just "Simple question" but "Label caption not displayed correctly" or something along these lines.
: Anyway, the problem is with "sleep", because it blocks all activity, also the updating of the Label1 caption. Better use a custom (self-made) procedure that allows Windows activity, e.g. Pauze(1000) with Application.ProcessMessages in its loop.

While the previous answer is valid it does not answer the question posed.
After each call to change the text in the label you MUST call Label1.Refresh to update the label before sleeping.

Related articles

       

Follow Ups