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


    这是与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.

  • 相关阅读:
    nefu17
    杭电1051
    杭电1050
    有关异或符号'^'在c++编程中的应用的讲解!!!
    杭电2095
    杭电2094
    关于set容器的简单讲解!!!
    拍拍开发
    收藏框架
    js form.submit() 无效
  • 原文地址:https://www.cnblogs.com/findumars/p/3654860.html
Copyright © 2020-2023  润新知