Error making Checkbox Visible

Asked

Viewed 67 times

0

I am 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 he gives a Acess Violation, when using debug and giving 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?

  • Checkbox esitem, are components created? It would not be the case to perform component search and so set?

  • Paste the entire code

  • They exist, they are only set to invisible. @Passella what most needs the code? I think all the information is there.

  • try: if Assigned(Checkbox[i]) then Checkbox[i]. Visible := True;

  • nothing happens @Passella

  • passes the entire code, it’s easier for someone to give you an answer

  • added @Passella

  • Voce does not guarantee that its local variable value is 2, Voce did not set the objects in the Checkbox vector, check whether the Findcomponent method actually returns anything, I hope it has helped

  • Returns because edits become visible, and the event is in the onchange so by adding 2 in the variable value, 2 edits become visible, and the same should be repeated for checkboxes.

Show 4 more comments

2 answers

1


create one where it will go through all 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;   

ai you can change according to your need by placing some more validations if necessary.

  • 1

    I had to adapt, but I followed that path, thank you.

0

I believe it may be a possibility this way, I have not tested 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;

Browser other questions tagged

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