type
TMyClass = class
procedure One;virtual;
end; type
TNewClass = class(TMyClass)
procedure One;virtual;
end;
//TmyClass中的one方法,是抽象的方法,你并没有实现它,
这话是什么意思,什么是是抽象的方法,什么是没有实现它,//
TMyClass = class
procedure One;virtual;
end; type
TNewClass = class(TMyClass)
procedure One;virtual;
end;
//TmyClass中的one方法,是抽象的方法,你并没有实现它,
这话是什么意思,什么是是抽象的方法,什么是没有实现它,//
解决方案 »
- AdoTable1.Filter的问题
- 删除DBGrid中的一条数据
- rave报表问题
- 请问,有没有可以播放REAL文件的VCL?
- 请问有没有是Delphi开发Web Service的?
- 寻Vcl控件
- 问一个非Delphi的问题-WindowsXP Professional 网络,ADSL,上网
- DLL中的Form的问题
- 如何同时修改多表中的相关联的字段?
- 新增或修改数据后,保存时出错,请各位高手帮我看一下!!!
- procedure func1; virtual;//virtual;这个是做什么的procedure func1; override;//override这个是做什么的
- 安装文件的制作?(用了SQL SERVER2000)
如果只是声明一下要用纯虚函数!
在基类中使用virtual,在派生类中使用override。如果忘记了这一点的话,会导致两个后果:
1.编译程序的时候会得到一个“Method ‘XXX’hides the virtual method of base type ‘XXX’”(尽管程序还可以运行
2.多态机制将无法正常工作。
type TAnimal=class
procedure Voice;virtual;
end; TDog=class(TAnimal)
procedure Voice;virtual;
end;implementationprocedure TAnimal.Voice;
begin
ShowMessage(‘Animal Voice’);
end;
procedure TDog.Voice;
begin
ShowMessage(‘Dog Voice’);
end;
procedure TForm1.FormCreate(Sender:TObject);
var
a : TAnimal;
begin
a := TAnimal.Create;
a.Voice;
a.Free;
a := TDog.Create;
a.Voice;
a.Free;
end;
运行这个程序的话,你会得到两个‘Animal Voice’。只要将声明中第二个virtual 改为override,你就能得到正确的结果:一个’Animal Voice’ 和一个’Dog Voice’
这个在Mastering Delphi中有详细的说明。。