Iherited 是一个保留字,在用在子类的(Method)的实现区里,当要设定子类某个方法的
实现内容,但这个方法实现区所包含的代码只会比父类所定义的实现内容多出一些代码,
而原本的部分仍然要延用时,就可以在类方法的实现区中用 Iherited 这个保留字
后面加上父类的成员函数的标识符(Identifier) ,并且给予适当参数.
而且,Iherited并非只能在override 的方法实现里,而且在子类设定的任何方法里使用
而且能调用父类任何成员函数.
实现内容,但这个方法实现区所包含的代码只会比父类所定义的实现内容多出一些代码,
而原本的部分仍然要延用时,就可以在类方法的实现区中用 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
unit Unit1;2

3
interface4

5
uses6
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,7
Dialogs, StdCtrls;8
type9
TPerson = class(TObject)10
public11
CONSTRUCTOR Create;12
FUNCTION Swim:String;13
{ Public declarations }14
end;15
type16
TET = class(TPerson)17
public18
Name: String;19
PROCEDURE Swim;20
PROCEDURE Swum; 21
{ Public declarations }22
end;23
type24
TForm1 = class(TForm)25
Button1: TButton;26
procedure Button1Click(Sender: TObject);27
private28
{ Private declarations }29
public30
{ Public declarations }31
end;32

33
var34
Form1: TForm1;35

36
implementation37

38
PROCEDURE TET.Swum;39
BEGIN40
ShowMessage('根据之前的资料 ' + #13+ #13 + '刚才');// + inherited Swim);41

42
end;43

44
PROCEDURE TET.Swim;45
BEGIN46
ShowMessage(Self.ClassName + '的 Create'+ #13+ #13);// + inherited Swim);47

48
end;49

50
FUNCTION TPerson.Swim:STRING;51
BEGIN52
result := '你游' + InputBox(Self.ClassName + '游泳池问卷','你游什么方式','蛙游') + '啊!';53
ShowMessage('问卷填好了!');54
end;55

56
CONSTRUCTOR TPerson.Create;57
BEGIN58
INHERITED ;59
ShowMessage('执行 ' + Self.ClassName + '的 Create'+ #13+ #13 +'欢迎光临Fish游泳池');60
end;61

62
{$R *.dfm}63

64
procedure TForm1.Button1Click(Sender: TObject);65
VAR66
aPerson: TPerson;67
theEt: Tet;68
begin69
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

浙公网安备 33010602011771号