比如,Panel1内有个Panel2,Panel2内有个Panel3,Panel3里面有个Button1,那么我怎么判断Button1是否包括在Panel1内,注意,镶套是随机的,不是固定的。谢谢

解决方案 »

  1.   

    Button1.Parent.Name就是所属容器名字,根据这个判断。
      

  2.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
        b:boolean;
        p:TWinControl;
        pName:string;
    begin
        b:=false;
        p:=button1;
        while pName<>self.Name do
        begin
            pName:=p.Parent.Name;
            if pName='Panel1' then
            begin
                b:=true;
                exit;
            end
            else
            begin
                p:=p.Parent;
            end;
        end;    if b=true then
            showmessage('True')
        else
            showmessage('False');
    end;我写的这个,但是跟踪下去的话,最后一步会跳出循环,不知道为什么,算法上我想应该是对的,你可以看一下