TComponent与TControl的区别?(100分)

  • 主题发起人 主题发起人 Afei1
  • 开始时间 开始时间
A

Afei1

Unregistered / Unconfirmed
GUEST, unregistred user!
问题如上:
 
所有可以装的上IDE的控件都是从TComponent下继承,,,
 
组件分两种:
WINDOWS组件和非WINDOWS组件
而WINDOWS组件又分两种:可视化组件(TControl)和非可视化组件(TComponent)
可视化组件是继承Tcontrol组件的,例如:Tbutton, Tedit,
非可视化组件是继承Tcomponent来的,例如:Ttimer.....[red][/red]
 
同意 6bytes ,说得很到位,楼主,回去多看看书,论坛上只能问个大概
详细的,要自已去找
 
查HELP
TControls是TComponent的子类。
Controls are visual components, meaning the user can see them and possibly
interact with them at runtime....(以下略)
也就是说TControls是可视控件的基类。既然是运行时可视的控件,
就有很多外观和交互方面的属性、方法。
TComponent是所有控件的基类,不关心可视化方面的东西。
所以如果你需要开发可视控件,就应当从TControls亦即其子类中继承开发。
如果开发非可视控件可以从TComponent继承开发。
 
首先谢谢楼上各位的回答
我现在要用到这样的一个功能
比如说我的窗体有一个TPageControl控件(三个页匡)和一个按钮,
在TPageControl的第一个页匡里面还有三个Tedit
Showmessage(IntToStr(Form1.ControlCount));
2
Showmessage(IntToStr(Form1.ComponentCount));
8
Showmessage(IntToStr(PageControl1.Pages[0].ControlCount));
3
Showmessage(IntToStr(PageControl1.Pages[0].ComponentCount));
0
我现在想问的是为什么第一个和最后一个会是2跟0
TPageControl和Tedit都是可视化控件啊
 
to 6bytes:
兄台的说法似乎有点问题。
VCL的类图结构
TObject
|
TPersisent
|
TComponent
|
TControl
|
--------------------
| |
TGraphicControl TWinControl
由此可见
VCL的控件分 可视化控件和非可视控件2类(这个分类法比较粗略),
可视控件又分 图形控件(继承于TGraphicControl)和
Window(继承于TWinControl)控件2种。
其他的就不多讲了。
 
各位高手能否回到我的问题上:
首先谢谢楼上各位的回答
我现在要用到这样的一个功能
比如说我的窗体有一个TPageControl控件(三个页匡)和一个按钮,
在TPageControl的第一个页匡里面还有三个Tedit
Showmessage(IntToStr(Form1.ControlCount));
2
Showmessage(IntToStr(Form1.ComponentCount));
8
Showmessage(IntToStr(PageControl1.Pages[0].ControlCount));
3
Showmessage(IntToStr(PageControl1.Pages[0].ComponentCount));
0
我现在想问的是为什么第一个和最后一个会是2跟0
TPageControl和Tedit都是可视化控件啊
 
同意tuti 我也觉得6bytes的理解有问题 只是在vcl中的层次不一样 不是可不可见的问题
control 是component的子集 每一个control必定是一个component
你上面的问题 这样理解
componentcount,comonents等都是对它的owner而言
而controlcount controls等是对parent而言的
在你的例子里
Showmessage(IntToStr(Form1.ControlCount));
2 说明parent是form1的control有两个
Showmessage(IntToStr(PageControl1.Pages[0].ComponentCount));
0
说明owner是pages的component没有 因为上面组件的owner是form1
 
对于一个form来说
owner是不是只有一个?
 
同意karxios的分析:
TComponent.Owner的Help中
“By default, a form owns all components that are on it.”
TControl.Parent
“The parent of a control is the control that contains the control”
可见.
ControlCount,ComponentCount的区别,不是 控件父类子类的关系,
而是基于component不同属性的组织形式的关系。
ComponentCount是基于TComponent.Owner的关系
ControlCount是基于TControl.Parent的关系
VCL HELP
Note: The Parent property declared in TControl is similar
to the Owner property declared in TComponent, in that
the Parent of a control frees the control just as the
Owner of a component frees that Component. However,
the Parent of a control is always a windowed control
that visually contains the control, and is responsible
for writing the control to a stream when the form is saved.
The Owner of a component is the component that was passed
as a parameter in the constructor and, if assigned, initiates
the process of saving all objects (including the control and
its parent) when the form is saved.
 
感谢karxios和tuti
你们的回答使我茅塞顿开
我的QQ是80685722,不知道可否交个朋友
谢谢
 
我先给分结帖了
 
多人接受答案了。
 
后退
顶部