Recent

Author Topic: (Solved)Components/Graphics Problem  (Read 176 times)

JLWest

  • Hero Member
  • *****
  • Posts: 934
(Solved)Components/Graphics Problem
« on: October 09, 2020, 10:08:46 pm »
The following code hides all the tlabels on a form and works fine. If I have a form with 35 tlabels is there a way to hide just very specific tlabels say 11 of the 35?



Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnHideClick(Sender: TObject);
  2.  var i : Integer;
  3.   begin
  4.        for i:= 0 to ComponentCount-1 do
  5.          if Components[i] is TLabel then begin
  6.           TLabel(Components[i]).Visible := False;
  7.         end;
  8. end;  

Thanks
« Last Edit: October 09, 2020, 10:52:14 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

howardpc

  • Hero Member
  • *****
  • Posts: 3583
Re: Components/Graphics Problem
« Reply #1 on: October 09, 2020, 10:20:04 pm »
One way would be to set the Tag property of all labels-to-be-hidden to some marker value.
Then  in your loop test the Tag value of each TLabel for the marker value and act accordingly.

JLWest

  • Hero Member
  • *****
  • Posts: 934
Re: Components/Graphics Problem
« Reply #2 on: October 09, 2020, 10:51:09 pm »
hi howardpc

Yes, Coded and tested. It works.

Thank You

Code: Pascal  [Select][+][-]
  1.       for i:= 0 to ComponentCount-1 do
  2.          if Components[i] is TLabel then begin
  3.           if TLabel(Components[i]).Tag =1 then begin
  4.              TLabel(Components[i]).Visible := False;
  5.           end;
  6.         end;                                                  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018