1type
2 TMan = class(Tobject)
3 public
4 PROCEDURE Dance;VIRTUAL;abstract; //定义为纯虚函数,待子类来覆盖
5 { Public declarations }
6 end;
7type
8 TEuropean = class(TMan)
9 public
10 PROCEDURE Dance;OVERRIDE; // TEuropean子类覆盖父类 TMan的Dance方法
11 // abstract,OVERRIDE是成对出现的
12 { Public declarations }
13 end;
14type
15 TNorthEuropean = class(TEuropean) //继承了 TEuropean,可以不用Override纯虚函数
16// PROCEDURE Dance;OVERRIDE; //还可以被孙类 TNorthEuropean所覆盖子类 TEuropean的Dance方法
17 end;
18type
19 TAsian = class(TMan)
20 public
21 PROCEDURE Dance;OVERRIDE; //必须Override纯虚函数 Dance
22 { Public declarations }
23 end;
24type
25 TForm1 = class(TForm)
26 Button1: TButton;
27 procedure Button1Click(Sender: TObject);
28 private
29 { Private declarations }
30 public
31 { Public declarations }
32 end;
33
34{ PROCEDURE TNorthEuropean.Dance; // TEuropean TManDance;
35BEGIN
36 ShowMessage('TNorthEuropean.Dance');
37end; }
38
39PROCEDURE TAsian.Dance; //TAsian的Dance 实现
40BEGIN
41 ShowMessage(self.ClassName + '对象 ' + #13 + #13 +
42 '执行 TAsian.Dance' + #13 + #13 +
43 '亚洲人爱跳探戈');
44end;
45
46PROCEDURE TEuropean.Dance; //TEuropean的Dance 实现
47BEGIN
48 ShowMessage(self.ClassName + '对象 ' + #13 + #13 +
49 '执行 TEuropean.Dance' + #13 + #13 +
50 '欧洲人爱跳拉丁舞');
51end;
52
53procedure TForm1.Button1Click(Sender: TObject);
54 VAR
55 SuperMan: TMan;
56begin
57 SuperMan := TEuropean.Create;
58 SuperMan.Dance; //调用的是TEuropean的Dance 方法
59 SuperMan.Free;
60
61 SuperMan := TNorthEuropean.Create;
62 SuperMan.Dance; //调用的是TEuropean的Dance 方法
63 SuperMan.Free;
64
65 SuperMan := TAsian.Create;
66 SuperMan.Dance; //调用的是TAsian的Dance 方法
67 SuperMan.Free;
68end;
69
70
2 TMan = class(Tobject)
3 public
4 PROCEDURE Dance;VIRTUAL;abstract; //定义为纯虚函数,待子类来覆盖
5 { Public declarations }
6 end;
7type
8 TEuropean = class(TMan)
9 public
10 PROCEDURE Dance;OVERRIDE; // TEuropean子类覆盖父类 TMan的Dance方法
11 // abstract,OVERRIDE是成对出现的
12 { Public declarations }
13 end;
14type
15 TNorthEuropean = class(TEuropean) //继承了 TEuropean,可以不用Override纯虚函数
16// PROCEDURE Dance;OVERRIDE; //还可以被孙类 TNorthEuropean所覆盖子类 TEuropean的Dance方法
17 end;
18type
19 TAsian = class(TMan)
20 public
21 PROCEDURE Dance;OVERRIDE; //必须Override纯虚函数 Dance
22 { Public declarations }
23 end;
24type
25 TForm1 = class(TForm)
26 Button1: TButton;
27 procedure Button1Click(Sender: TObject);
28 private
29 { Private declarations }
30 public
31 { Public declarations }
32 end;
33
34{ PROCEDURE TNorthEuropean.Dance; // TEuropean TManDance;
35BEGIN
36 ShowMessage('TNorthEuropean.Dance');
37end; }
38
39PROCEDURE TAsian.Dance; //TAsian的Dance 实现
40BEGIN
41 ShowMessage(self.ClassName + '对象 ' + #13 + #13 +
42 '执行 TAsian.Dance' + #13 + #13 +
43 '亚洲人爱跳探戈');
44end;
45
46PROCEDURE TEuropean.Dance; //TEuropean的Dance 实现
47BEGIN
48 ShowMessage(self.ClassName + '对象 ' + #13 + #13 +
49 '执行 TEuropean.Dance' + #13 + #13 +
50 '欧洲人爱跳拉丁舞');
51end;
52
53procedure TForm1.Button1Click(Sender: TObject);
54 VAR
55 SuperMan: TMan;
56begin
57 SuperMan := TEuropean.Create;
58 SuperMan.Dance; //调用的是TEuropean的Dance 方法
59 SuperMan.Free;
60
61 SuperMan := TNorthEuropean.Create;
62 SuperMan.Dance; //调用的是TEuropean的Dance 方法
63 SuperMan.Free;
64
65 SuperMan := TAsian.Create;
66 SuperMan.Dance; //调用的是TAsian的Dance 方法
67 SuperMan.Free;
68end;
69
70