Execute procedure in Delphi loop

Hi I have another question for Experts
I have an ordinary loop in Delphi code and I want to execute some simple procedure:
Ex.
Var
str : string;
chquery.Active := false;
chquery.SQL.Text:='SELECT * from table1';
chquery.ExecSQL;
chquery.First;
while not chquery.Eof do
  begin
    str := chquery.FieldByName('title').AsString;
   Label1.Caption  := str;
   sleep(2000);
   chquery.Next;
  end;

I wann for each record Label1 to show me field Title, but in my case it show only the last one when the loop is end
alexk_66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
When you are in a loop the window cannot be updated unless you add a line after setting the caption:

Application.ProcessMessages;

Open in new window


Allowing your program to "repaint" the window each loop.
Tryn adding this line after

Label1.Caption  := str;

Open in new window


And you can reduce the sleep time (there is no need of sleep to make it work)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukSoftware architectCommented:
This - should be fine in your case - without: Application.ProcessMessages.
Label1.Caption  := str;
Label1.Refresh;

Open in new window

...and if you open query - then you don't need to execute:
chquery.SQL.Text:='SELECT * from table1';
chquery.Open;

Open in new window

Sql update,insert or delete - should call ExecSQL.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.