virtual override
//不带virtual override的type TForm9 = class(TForm) btn1: TButton; mmo1: TMemo; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; a = class procedure funct1; // virtual; end; b = class(a) procedure funct1;// override; end; var Form9: TForm9; implementation {$R *.dfm} procedure TForm9.btn1Click(Sender: TObject); var b1: b; a1: a; begin b.Create.funct1; //a b a(b.Create).funct1; //a a.Create.funct1; //a end; { a } procedure a.funct1; begin Form9.mmo1.Lines.Add('a'); end; { b } procedure b.funct1; begin inherited; Form9.mmo1.Lines.Add('b'); end; end.
//带 type TForm9 = class(TForm) btn1: TButton; mmo1: TMemo; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; a = class procedure funct1;virtual; end; b = class(a) procedure funct1; override; end; var Form9: TForm9; implementation {$R *.dfm} procedure TForm9.btn1Click(Sender: TObject); var b1: b; a1: a; begin a(b.Create).funct1; //也是输出a b b.Create.funct1; // a b end; { a } procedure a.funct1; begin Form9.mmo1.Lines.Add('a'); end; { b } procedure b.funct1; begin inherited; Form9.mmo1.Lines.Add('b'); end; end.
实际中:
function GetSubForm(SubFormName:string):TForm;virtual;abstract;
//子类中
function GetSubForm(SubFormName:string):TForm;override;