首页 > 其他 > 详细

控件构造函数需要的是AOwner TComponent,而不是Parent

时间:2015-07-26 00:26:34      阅读:192      评论:0      收藏:0      [点我收藏+]

普通控件都只有一个构造函数,但是这个构造函数却强迫指定AOwner,也就是说,VCL希望将所有控件(至少是所有可视化控件)全部置于它的管理之下。至于到底显示不显示,那是另一个层次的问题。这个问题其实挺简单,但我就是希望强化一下这个概念。简单观察一下TLabel的构造函数就可以明白这一点:

constructor TCustomLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csReplicatable];
  Width := 65;
  Height := 17;
  FAutoSize := True;
  FShowAccelChar := True;
  { The "default" value for the Transparent property depends on
    if you have Themes available and enabled or not. If you have
    ever explicitly set it, that will override the default value. }
  if ThemeServices.ThemesEnabled then
    ControlStyle := ControlStyle - [csOpaque]
  else
    ControlStyle := ControlStyle + [csOpaque];
end;

 

控件构造函数需要的是AOwner TComponent,而不是Parent

原文:http://www.cnblogs.com/findumars/p/4676851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!