Error making CheckBox visible

0

I'm using the following code to make CheckBox visible.

CheckBox: Array[1..15] of TcheckBox;


procedure TForm1.edt_variavelChange(Sender: TObject);
var valor,x,i  : integer;
 if valor = 2 then
    begin
         for i := 1 to 2 do
           begin
              TEdit(FindComponent('edt_variavel'+IntToStr(i))).Visible := true
              CheckBox[i].Visible := true;
     end;

But it gives a Acess Violation , when using the debug and give a BREAK in the error I am directed to this code of Vcl.Controls

procedure TControl.SetVisible(Value: Boolean);
begin
  if FVisible <> Value then
  begin
    VisibleChanging;
    FVisible := Value;
    Perform(CM_VISIBLECHANGED, Ord(Value), 0);
    RequestAlign;
  end;
end;

How can I fix this error?

    
asked by anonymous 02.02.2016 / 14:11

2 answers

1

create a where it will go through all the components if it is checkbox activate it as follows:

for i := 0 to ComponentCount - 1 do
    begin
       if Components[i] is TCheckBox then
          TCheckBox(Components[i]).Visible := true;
    end;   

there you can change according to your need, putting some more validations if necessary.

    
09.02.2016 / 15:44
0

I think it might be a possibility this way, I did not test the code:

procedure SetaCheckBox (bOp : Boolean);
var
    nmComp : TComponent;
    i : integer;
begin
    for i := 0 to Form1.ComponentCount-1 do
    begin
        nmComp := Form1.FindComponent(Form1.Components[i].Name);
        if Assigned (nmComp) and  (nmComp is TCheckBox) then
                TCheckBox(nmComp).Visible := bOp;
    end;
end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
    SetaCheckBox (false);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
        SetaCheckBox (True);

end;
    
02.02.2016 / 14:52