谁来解释一下inherited起什么作用?(300)

T

tseug

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TImage.Paint;var Save: Boolean;begin if csDesigning in ComponentState then with inherited Canvas do begin Pen.Style := psDash
Brush.Style := bsClear
Rectangle(0, 0, Width, Height)
end
Save := FDrawing
FDrawing := True
try with inherited Canvas do StretchDraw(DestRect, Picture.Graphic)
finally FDrawing := Save
end;end;
 
inherited Canvas 表示Canvas是由父类继承的,书写习惯,不要也不影响
 
inherited 取到调用父类的方法~~的作用~不影响~
 
感谢楼上的参与,这段代码是Delphi VCL源代码摘出的一部分,完整的可以查看VCL,我想要的答案应该严谨,有所依据
 
这个地方不要并不影响.他本身并没有定义Canvas属性
 
如果是在函数或者过程中,单独一行inherited,则当前函数或者过程是从父类继承下来的,该行的作用,是执行该函数在父类中定义的过程体。如果inherited 属性A:表示取得父类中的 属性A如果inherited 过程A:表示执行父类中的 过程A如果父类中定义了一个属性A,当前子类中又定了一个属性A,则此时 inherited 属性A 和 属性A,就分别表示父类的属性A和当前子类的属性A,同理,对于函数或者过程,也是一样的。要不要是不影响的,这种说法有些欠妥。
 
楼上各位,我想知道你们的解答的依据是什么,是联机帮助,还是其他什么资料?
 
以前我们培训过,培训完成后,当时还特地测试的,之后也用DELPHI用了9年了,开发过程中,也是这么开发的。此外,多看看delphi本身的SysUtils单元和Classes单元,对你学习Delphi很有帮助的。
 
或者,你也可以写个代码,通过F7测试跟踪一下,你就可以发现Delphi是如何调用的了。
 
to: znxia多谢指点,我会按你的建议学习Delphi的。不过,你还是没有说出来你的依据。我今天问这个问题就是想刨根问底,不然我也没必要问这个问题了,你觉得呢?多说一句,如果我没有自己测试,我肯定不会问这个问题,我看了他的汇编代码,知道他的作用,但是我没有在文档中找到任何有关的说明。
 
依据?我使用D6年,大大小小的项目也做了10多个,VCL源码不敢说100%看完,至少看了有80%.资料必不可少,自己动手也很重要,很多东西都是在资料上找不到的
 
希望你别让我去翻译它。
 
delphi7菜单 help/Delphi Help,弹出界面,输入 inherited (reserved word),显示如下信息:The reserved word inherited plays a special role in implementing polymorphic behavior. It can occur in method definitions, with or without an identifier after it.If inherited is followed by the name of a member, it represents a normal method call or reference to a property or field--except that the search for the referenced member begins with the immediate ancestor of the enclosing method's class. For example, wheninherited Create(...);occurs in the definition of a method, it calls the inherited Create.When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method or, if the enclosing method is a message handler, to the inherited message handler for the same message. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called. For example,inherited;occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.
 
学习中~~`
 
我不懂E文,麻烦大家告诉我究竟那句话说的是: 一个属性前面加上 inherited 表示调用父类的 属性?
 
If inherited is followed by the name of a member, it represents a normal method call or reference to a property or field--except that the search for the referenced member begins with the immediate ancestor of the enclosing method's class.这句说来惭愧,帮助里很多东西我都没看过
 
if inherited is followed by the name of a member, it represents a normal method call or reference to a property or field--except that the search for the referenced member begins with the immediate ancestor of the enclosing method's class---------------followed:跟随name :名称member:成员(类的过程、函数、属性都是类的成员)represents :表现,描绘,声称reference :提及,设计,参考property :属性********search :查找referenced :参考的,引用的immediate 直接的,紧接的,紧靠的ancestor 祖先(父类)拿你的分,真的很不容易
 
不好意思,我第一次看帮助时,没注意这么一段,后来就想当然了,丢人。感谢大家的关注!
 

Similar threads

I
回复
0
查看
577
import
I
I
回复
0
查看
600
import
I
I
回复
0
查看
706
import
I
I
回复
0
查看
425
import
I
顶部