FindComponent是TComponent的方法,TComponent有FComponents,用来管理控件,你用FindComponent就需要FComponents的支持,FComponents怎么来的呢?他是一个TList,自然需要你创建然后insert了,对于Tpanel,如果没有动态创建的控件,你用FindComponent有什么意义呢  
  FComponents里面应该是空的,就算是TButton也应该找不到的!  
  所以如果用FindComponent,就只能用from,不能用panel.

  Panel1->Components表示被Panel1拥有(Owner)的组件,而我们拖放组件到Panel1上时(比如:TButton),TButton的Owner其实默认为TForm,所以Panel1->ComponentCount还是为零;如果我们动态生成TButton   *btn1=TButton(Panel1);这时Panel1->ComponentCount才有意义。  
   
      我们拖放组件到Panel1上时,只是说明组件的Parent(TControl类型)为Panel1   ,所以通过Panel1->Controls可以查到Parent为Panel1的组件。

Button隶属于:TObject->TPersistent->TComponent->TControl->TWinControl->TButtonControl  
  Image隶属于:TObject->TPersistent->TComponent->TControl->TGraphicControl  
  SpeedButton隶属于:TObject->TPersistent->TComponent->TControl->TGraphicControl  
   
  按照C++Builder的规定,TWinControl是指那些在运行期可见的组件,而TGraphicControl属于运行期可见的图形组件,尽管具有相同的祖先,但两者属于不同的类.

FindComponent是TComponent的方法,TComponent有FComponents,用来管理控件,你用FindComponent就需要FComponents的支持,FComponents怎么来的呢?他是一个TList,自然需要你创建然后insert了,对于Tpanel,如果没有动态创建的控件,你用FindComponent有什么意义呢  
  FComponents里面应该是空的,就算是TButton也应该找不到的!  
  所以如果用FindComponent,就只能用from,不能用panel.

      if   FindChildControl('button1')<>nil   then  
          AButton:=FindChildControl('button1')   as   TButton;   //用as强制  

FindComponent,是Owner,如果你的Shape是设计期放上去的,那么其Owner就是窗体,用窗体的FindComponent肯定可以找到。

如果你的Shape是运行期创建的,那么必须指定其Owner和Parent,这样,才可以找得到。

而且:如果你放上去的是TWinControl的继承类,那么用FindChildControl就可以找到,否则就找不到。
posted on 2008-09-30 15:24  yxbsmx  阅读(1365)  评论(0编辑  收藏  举报