Label - for loop lazarus / 31-LCL ---------------------------------------------------------------------- tuxmartin · 2011-08-26 20:02 I need clear a lot of Labels. I use this code: Code: [Select]procedure TForm1.clearLabel; begin  Label36.Caption := ' ';  Label37.Caption := ' ';  Label38.Caption := ' ';  Label39.Caption := ' ';  Label40.Caption := ' ';  Label41.Caption := ' ';  Label42.Caption := ' ';  Label43.Caption := ' ';  Label44.Caption := ' ';  Label45.Caption := ' '; end;it works. How can I do it with for loop? It doesn't works: Code: [Select]procedure TForm1.clearLabel; var  i: integer; begin  for i := 36 to 45 do  begin    Label[i].Caption := ' ';  end; end; ---------------------------------------------------------------------- eny · 2011-08-26 20:27 There have been many posts on this subject. Unfortunately the search function doesn't deliver in this case. Code: [Select]for i := 0 to ComponentCount-1 do     if Components[i] is TLabel then       (Components[i] as TLabel).Caption := '42'; ---------------------------------------------------------------------- IPguy · 2011-08-26 21:49 Really?  You can do that? So, if I had a scattered set of dissimilar components with a similar function, as long as I could find something similar in the attributes (like a portion of their name...), I could enable / disable them using this method.  Neat.  Thank you for that hint. ---------------------------------------------------------------------- typo · 2011-08-26 22:02 Code: [Select]procedure TForm1.clearLabel; var  i: integer; begin  for i := 36 to 45 do  begin    (FindComponent('Label' + IntToStr(i)) as TLabel).Caption := ' ';  end; end; ---------------------------------------------------------------------- User137 · 2011-08-27 04:12 Or you can manually create the labels runtime. Create them in forms onCreate. In cases like this i assume the positions are relative to each other so that should be very simple. Code: [Select]var labels: array[0..40] of TLabel; ---------------------------------------------------------------------- eny · 2011-08-27 08:17 Or you can create your own component iterator so you can do something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i with TMyComponentIterator.Instantiate(Self, TLabel) do  while HasNext do  with NextItem as TLabel do      if Tag >= 36 and Tag <= 45 then      Caption := '';  or another approach Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ClearLabel(pLabel: TLabel);begin  if pLabel.Tag >= 36 and pLabel.Tag <= 45 then    pLabel.Tag := ''end; .../* Your own container iterator class */with TMyOtherContainerIterator.Instantiate(Self, TLabel, @ClearLabel) do  VisitAll;