Problem with caption a text(Label) or edit a text(Editbox) in Loop statement lazarus / 12-Debugger ---------------------------------------------------------------------- nocuttree · 2014-09-05 16:12 I am a new member so I sorry all member! I have a button1, label1, edir1 my code: Quoteprocedure TForm1.Button1Click(Sender: TObject); var a: integer; begin   for a:=1 to 10000 do   begin   Label1.caption:=inttostr(a);   Edit1.text:=inttostr(a);   delay(1000);   end; end; I want to after a second it caption a but it finish loop statement it caption 10000. Sorry my English, thanks all! ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-05 16:22 You're not giving the OS any chance to Paint the updates... You've got a couple of choices.  Call Application.ProcessMessages once per loop (allow all pending Paint messages to be performed automatically), or manually force the Label and Edit to repaint themselves.  See below for both options... Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var a: integer; begin   for a:=1 to 10000 do   begin   Label1.caption:=inttostr(a);   Edit1.text:=inttostr(a);   Application.ProcessMessages;  //  <---  This will allow all pending paint operations to complete   //Label1.Invalidate;          //  <--- If you don't want to allow pending messages to be processed, then this approach may force the label to repaint   //Edit1.Invalidate;           //  <---  I'm less certain if this approach will work on a TEdit, you may need to use ProcessMessages   delay(1000);   end; end; ---------------------------------------------------------------------- nocuttree · 2014-09-05 16:59 Quote from: Mike.Cornflake on September 05, 2014, 06:22:51 pmYou're not giving the OS any chance to Paint the updates... You've got a couple of choices.  Call Application.ProcessMessages once per loop (allow all pending Paint messages to be performed automatically), or manually force the Label and Edit to repaint themselves.  See below for both options... Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var a: integer; begin   for a:=1 to 10000 do   begin   Label1.caption:=inttostr(a);   Edit1.text:=inttostr(a);   Application.ProcessMessages;  //  <---  This will allow all pending paint operations to complete   //Label1.Invalidate;          //  <--- If you don't want to allow pending messages to be processed, then this approach may force the label to repaint   //Edit1.Invalidate;           //  <---  I'm less certain if this approach will work on a TEdit, you may need to use ProcessMessages   delay(1000);   end; end;Thasks you very much! ---------------------------------------------------------------------- nocuttree · 2014-09-05 18:24 It works with "for... to....do" but "while......... do.........."? Thanks you! ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-05 18:27 Quote from: nocuttree on September 05, 2014, 08:24:49 pmIt works with "for... to....do" but "while......... do.........."? Doesn't matter which loop method you use.  After you've finished setting all your properties (.text, .caption etc), call Application.ProcessMessages :-) Something to be wary of (which is why you may want to investigate the .invalidate option instead) is that Application.ProcessMessages will process ALL pending messages, include any button presses the user may do.  So, if you run your loop in one button press, then call Application.ProcessMessages, the user will have an opportunity to continue interacting with your form while your first loop is cycling... If .Invalidate doesn't work, then try .Repaint or .Update instead.  I must admit, I'm pretty terrible when it comes to working out which one to use, I just keep trying one then the other until I find something which works :-) ---------------------------------------------------------------------- nocuttree · 2014-09-06 02:39 Thanks you! I am sorry, error come from another place. ---------------------------------------------------------------------- BigChimp · 2014-09-06 14:10 Could you please start a new thread when you have a new problem? That will hopefully attract more people, make it easier for other people having the same problem to search the forum, and avoid confusion when responding to your questions... PS: Looking at the code it should work as long as you click button1 first... I may be missing something obvious here (haven't compiled the code either) ---------------------------------------------------------------------- nocuttree · 2014-09-06 14:47 Quote from: BigChimp on September 06, 2014, 04:10:26 pmCould you please start a new thread when you have a new problem? That will hopefully attract more people, make it easier for other people having the same problem to search the forum, and avoid confusion when responding to your questions... PS: Looking at the code it should work as long as you click button1 first... I may be missing something obvious here (haven't compiled the code either) Thanks you! I will start a new thread in next post! Sorry all!