这是与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.
来源:https://www.cnblogs.com/findumars/p/3654860.html