设计控件时,谁能给我解释一下inherited的用法? ( 积分: 100 )

  • 主题发起人 主题发起人 taibu
  • 开始时间 开始时间
T

taibu

Unregistered / Unconfirmed
GUEST, unregistred user!
看到一个例子代码如下:<br>type<br>&nbsp;TMyCmb&nbsp;=&nbsp;class(TWinControl)<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;FEdit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;TEdit;<br>&nbsp;&nbsp;......<br>procedure&nbsp;TMyCmb.EditingChange(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;inherited&nbsp;&nbsp;ReadOnly&nbsp;:=&nbsp;not&nbsp;FDataLink.Editing;<br>end;<br><br>我想向各位请教的是,上面代码中,inherited&nbsp;&nbsp;ReadOnly&nbsp;:=&nbsp;not&nbsp;FDataLink.Editing;<br>这行能否写成:<br>procedure&nbsp;TMyCmb.EditingChange(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;inherited&nbsp;;&nbsp;<br>&nbsp;&nbsp;FEdit.ReadOnly&nbsp;:=&nbsp;not&nbsp;FDataLink.Editing;<br>end;<br>写到同一行与分两分写有何区别?
 
procedure&nbsp;TMyCmb.EditingChange(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;inherited&nbsp;&nbsp;ReadOnly&nbsp;:=&nbsp;not&nbsp;FDataLink.Editing;<br>end;<br>这里应该编译通不过吧<br>iherited&nbsp;property&nbsp;说明使用祖先类的属性,但是TMyCmb的祖先类中没有ReadOnly属性,<br>所以这里编译通不过:Undeclared&nbsp;identifier:&nbsp;'ReadOnly'
 
inherited&nbsp;是直接使用祖先类的属性、方法,<br>type&nbsp;<br>&nbsp;&nbsp;TMyEdit&nbsp;=&nbsp;class(TEdit)<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;fReadOnly&nbsp;:&nbsp;boolean;<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;constructor&nbsp;Create(AOwner:&nbsp;TComponent);override;<br>&nbsp;&nbsp;&nbsp;&nbsp;destructor&nbsp;&nbsp;Destroy;override;<br>&nbsp;&nbsp;end;<br><br>................<br><br>constructor&nbsp;TMyEdit.Create(AOwner:&nbsp;TComponent);<br>begin<br>&nbsp;&nbsp;inherited&nbsp;Create(AOwner:&nbsp;TComponent);<br>&nbsp;&nbsp;fReadOnly&nbsp;:=&nbsp;not&nbsp;(inherited&nbsp;ReadOnly);<br>end;<br><br>destructor&nbsp;TMyEdit.Destroy;<br>begin<br>&nbsp;&nbsp;.......<br>&nbsp;&nbsp;inherited;&nbsp;&nbsp;&nbsp;&nbsp;//inherited&nbsp;Destroy;<br>end;
 
如果光是一个inherited;后面不加ReadOnly&nbsp;:=&nbsp;not&nbsp;FDataLink.Editing的话,那这时的inherited继承的是哪些属性?
 
多人接受答案了。
 
后退
顶部