Loop to make edits invisible

2

I have the following way, to make edits invisible.

edt_raster5.visible := false;
edt_raster6.visible := false;
edt_raster7.visible := false;
edt_raster8.visible := false;
edt_raster9.visible := false;

Is there a way to use a loop to make it easier? I know it's very simple but I'm not getting it right ... I tried the following but it clearly did not work out.

for i := 1 to 9

edt_raster[i].visible := false;
    
asked by anonymous 29.01.2016 / 14:17

3 answers

4

You can scan the Components property of your Form where all its components are stored and see which are Edit to change. Example:

  for I := 0 to Form1.ComponentCount - 1 do
  begin
    if Form1.Components[I] is TEdit then
    TEdit(Form1.Components[i]).Visible = false;
  end;
    
29.01.2016 / 16:35
1
for i := 1 to 9 do
    begin
    TEdit(FindComponent('edt_variavel'+IntToStr(i))).Visible := false;
    end;

Resolved my issue.

    
29.01.2016 / 15:43
0

I usually work this way

for i := 0 to ComponentCount - 1 do     // percore todos os componentes do form
    begin
       if Components[I] is TEdit then   // se for TEdit
          begin
              if (TEdit(Components[i]).name = 'edtDescricao') then  // se o componente for igual ao nome
                 TEdit(Components[i]).visible := True 
              else
                 TEdit(Components[i]).visible := False;
          end;
    end;
    
09.02.2016 / 15:05