Hello. I'm just learning Delphi and I wrote this simple code to respond to the On Click Event of one Button.
I don't understand why while running the program first the for..loop is executed and only after this the Label1.Caption is updated. I was expecting the opposite behaviour (first label and then for..loop). Is this a problem related to the use of Sleep? I didn't modify any setting. I'm using Delphi 7.
Thanks for reading!
(this procedure simply displays a countdown checking every second a different itemof a radiogroup):
procedure TForm1.ButtonForClick(Sender: TObject);
var
I: Integer;
begin
Label1.Caption := 'For..Loop is running';
for I := (RadioGroup1.Items.Count) downto 0 do
begin
RadioGroup1.ItemIndex := I - 1;
Sleep(1000);
end;
end;
I don't understand why while running the program first the for..loop is executed and only after this the Label1.Caption is updated. I was expecting the opposite behaviour (first label and then for..loop). Is this a problem related to the use of Sleep? I didn't modify any setting. I'm using Delphi 7.
Thanks for reading!
(this procedure simply displays a countdown checking every second a different itemof a radiogroup):
procedure TForm1.ButtonForClick(Sender: TObject);
var
I: Integer;
begin
Label1.Caption := 'For..Loop is running';
for I := (RadioGroup1.Items.Count) downto 0 do
begin
RadioGroup1.ItemIndex := I - 1;
Sleep(1000);
end;
end;