实现内容,但这个方法实现区所包含的代码只会比父类所定义的实现内容多出一些代码,
而原本的部分仍然要延用时,就可以在类方法的实现区中用 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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81
