我在一个groupbox 中放入几个shape
varsh:TControl;
begin
  sh:=grp1.FindChildControl('shape1');
  if grp1.FindChildControl('shape1')<>nil then
  ShowMessage('sss');
end;
为什么找不到shape呢,而返回值是Nil

解决方案 »

  1.   

    mastersky(浪) :
    才试过一样
      

  2.   

    FindChildControl only locates immediate children of the control. It can't find a control that is a child of one of the control's children.//重点在这句看看这个注视吧,你直接把shape放到form上,然后
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if assigned(self.FindChildControl('button2')) then
        ShowMessage('sss');
    end;这样看看就明白什么意思了。
      

  3.   

    xixuemao(动感超淫) :
    我有看过Help
    a control's children 是如何定义的呢,是指Pearent,还是Owner?
    我实际上把shape放在了Groupbox里,而GroupBox又放在Form上,并且
    Shape和GroupBox都是动态生成的,那我该如何操作shape?
      

  4.   

    用FindComponent,无论如何也找得到。
      

  5.   

    FindComponent,是Owner,如果你的Shape是设计期放上去的,那么其Owner就是窗体,用窗体的FindComponent肯定可以找到。如果你的Shape是运行期创建的,那么必须指定其Owner和Parent,这样,才可以找得到。而且:如果你放上去的是TWinControl的继承类,那么用FindChildControl就可以找到,否则就找不到。
      

  6.   

    a control's children 是如何定义的呢,是指Pearent,还是Owner?
    〉〉指Parent,但是这个要是从TWinControl下继承下来的才可以找到。我实际上把shape放在了Groupbox里,而GroupBox又放在Form上,并且
    Shape和GroupBox都是动态生成的,那我该如何操作shape?
    〉〉如果你指定了它的Owner是谁,就用谁的FindComponent.
      

  7.   

    谢谢各位
    谢谢mastersky(浪)的详细解答!