Delphi里可将纯虚类实例化,还可调用非虚函数

Deadly 提交于 2020-03-04 07:55:08

这是与Java/C++的巨大不同。目前还没仔细想这个特征与TClass之间的联系,先记住结论再说。以后再回来修改这个帖子。

 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

TXXX = class(TObject)
private
FList: TList;
protected
function PeekItem: Pointer; virtual; abstract;
property List: TList read FList;
public
constructor Create;
destructor Destroy; override;
procedure Show;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
VAR
x: TXXX;
begin
x:=TXXX.Create; // 实例化一点问题没有
x.PeekItem; // 调用纯虚方法出错 // 调用Show方法正确执行
end;

{ TXXX }

constructor TXXX.Create;
begin
inherited;
end;

destructor TXXX.Destroy;
begin
inherited;
end;

procedure TXXX.Show;
begin
ShowMessage('dddd');
end;

end.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!