Loop to make edits invisible

Asked

Viewed 381 times

2

I have the following way, to make the 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....

for i := 1 to 9

edt_raster[i].visible := false;

3 answers

4


You can sweep the property Components from your Form where all its components are stored and check which ones 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;
  • I thought about it, but I didn’t want to make all the edits invisible, only the ones with a certain name.

  • I get it, so use the method that Voce posted, or you could scan all the components, get all the Edit, and check the name.

  • Yes, it worked, but I tried to do the same thing as the checkbox, he read the error....

1

for i := 1 to 9 do
    begin
    TEdit(FindComponent('edt_variavel'+IntToStr(i))).Visible := false;
    end;

You saved my trouble.

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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.