inherited使用举例

Iherited 是一个保留字,在用在子类的(Method)的实现区里,当要设定子类某个方法的
 实现内容,但这个方法实现区所包含的代码只会比父类所定义的实现内容多出一些代码,
 而原本的部分仍然要延用时,就可以在类方法的实现区中用 Iherited 这个保留字
 后面加上父类的成员函数的标识符(Identifier)  ,并且给予适当参数.
 而且,Iherited并非只能在override 的方法实现里,而且在子类设定的任何方法里使用
 而且能调用父类任何成员函数.
 1 unit  Unit1;
 2
 3 interface
 4
 5 uses
 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 7   Dialogs, StdCtrls;
 8 type
 9   TPerson  =   class (TObject)
10    public
11   CONSTRUCTOR  Create;
12   FUNCTION Swim:String;
13      {  Public declarations  }
14    end ;
15 type
16   TET  =   class (TPerson)
17    public
18   Name: String;
19   PROCEDURE  Swim;
20   PROCEDURE  Swum; 
21      {  Public declarations  }
22    end ;
23 type
24   TForm1  =   class (TForm)
25     Button1: TButton;
26      procedure  Button1Click(Sender: TObject);
27    private
28      {  Private declarations  }
29    public
30      {  Public declarations  }
31    end ;
32
33 var
34   Form1: TForm1;
35
36 implementation
37
38 PROCEDURE  TET.Swum;
39 BEGIN
40   ShowMessage( ' 根据之前的资料  '   +  # 13 +  # 13   +   ' 刚才 ' ); //   +   inherited  Swim);
41
42 end ;
43
44 PROCEDURE  TET.Swim;
45 BEGIN
46  ShowMessage(Self.ClassName  +   ' 的 Create ' +  # 13 +  # 13 ); //    +   inherited  Swim);
47
48 end ;
49
50 FUNCTION TPerson.Swim:STRING;
51 BEGIN
52   result : =   ' 你游 '   +  InputBox(Self.ClassName  +   ' 游泳池问卷 ' , ' 你游什么方式 ' , ' 蛙游 ' +   ' 啊! ' ;
53 ShowMessage( ' 问卷填好了! ' );
54 end ;
55
56 CONSTRUCTOR  TPerson.Create;
57 BEGIN
58   INHERITED ;
59   ShowMessage( ' 执行  '   +  Self.ClassName  +   ' 的 Create ' +  # 13 +  # 13   + ' 欢迎光临Fish游泳池 ' );
60 end ;
61
62 { $R *.dfm }
63
64 procedure  TForm1.Button1Click(Sender: TObject);
65  VAR
66   aPerson: TPerson;
67   theEt: Tet;
68 begin
69   aPerson : =  TPerson.Create;
70   aPerson.Swim;
71   aPerson.Free;
72   theEt : =  TET.Create;
73   theEt.Name : =   ' 外星人ET ' ;
74   theEt.Swim;
75   theEt.Swum;
76   theEt.Free;
77 end ;
78
79 end .
80
81

转载于:https://www.cnblogs.com/dreamszx/archive/2009/09/22/1572007.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值