Forum > LCL

When does Label.caption update?

(1/2) > >>

OC DelGuy:
Hi y'all!
Ok, so I wrote this little procedure to give a preview of some questions that will appear later on in the program and their specific category codes.

Ques is a TLabel and Start is a TButton.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.StartClick(Sender: TObject);begin  For x:=1 to 24 do    Begin      Ques.caption:= Questions[x] +'   '+QuestionCats[x];      Sleep(500);    end;end;   The problem is that when I click the button, some time goes by and then the LAST question with it's appropriate code appears.
I would have thought that the first question and its code appears and the program waits a bit, then the second question and its code appears and it waits until the last question.  Why doesn't the new label caption appear each iteration of the for loop?

dbannon:
Lazarus updates screen content "when it gets around to it" - things like that are put in a queue and done when the system has some time on its hands.

Call Application.ProcessMessages; just before the sleep command to ensure the queue is processed when you want it done.

Davo
 

OC DelGuy:
Yep, That did it!  Thanks Davo!

jamie:
Or MYLabel.Repaint;

which maybe better to avoid clashes with messages in the que..

dbannon:
Yes, repaint would be a bit (or a lot) less forceful.  I tend to think of Application.ProcessMessages as a general solution to that sort of problem. OC DelGuy, I'd try Jamie's way if I was you ...

Davo

Navigation

[0] Message Index

[#] Next page

Go to full version