关于FindChildControl方法,马上揭帖!!!!

elite01 2005-10-27 05:24:15
我在一个groupbox 中放入几个shape
var

sh:TControl;
begin
sh:=grp1.FindChildControl('shape1');
if grp1.FindChildControl('shape1')<>nil then
ShowMessage('sss');
end;
为什么找不到shape呢,而返回值是Nil
...全文
214 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
elite01 2005-10-28
  • 打赏
  • 举报
回复
谢谢各位
谢谢mastersky(浪)的详细解答!
mastersky 2005-10-28
  • 打赏
  • 举报
回复
a control's children 是如何定义的呢,是指Pearent,还是Owner?
〉〉指Parent,但是这个要是从TWinControl下继承下来的才可以找到。

我实际上把shape放在了Groupbox里,而GroupBox又放在Form上,并且
Shape和GroupBox都是动态生成的,那我该如何操作shape?
〉〉如果你指定了它的Owner是谁,就用谁的FindComponent.
mastersky 2005-10-28
  • 打赏
  • 举报
回复
FindComponent,是Owner,如果你的Shape是设计期放上去的,那么其Owner就是窗体,用窗体的FindComponent肯定可以找到。

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

而且:如果你放上去的是TWinControl的继承类,那么用FindChildControl就可以找到,否则就找不到。
linzhengqun 2005-10-27
  • 打赏
  • 举报
回复
用FindComponent,无论如何也找得到。
elite01 2005-10-27
  • 打赏
  • 举报
回复
xixuemao(动感超淫) :
我有看过Help
a control's children 是如何定义的呢,是指Pearent,还是Owner?
我实际上把shape放在了Groupbox里,而GroupBox又放在Form上,并且
Shape和GroupBox都是动态生成的,那我该如何操作shape?
xixuemao 2005-10-27
  • 打赏
  • 举报
回复
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;

这样看看就明白什么意思了。
elite01 2005-10-27
  • 打赏
  • 举报
回复
mastersky(浪) :
才试过一样
mastersky 2005-10-27
  • 打赏
  • 举报
回复
试试:FindComponent
elite01 2005-10-27
  • 打赏
  • 举报
回复
up!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧