type
TaClass = class
procedure iProc; virtual;
procedure A;
end;
type
TbClass = class(TaClass)
procedure iProc; override; //将子对象赋给父对象,由父对象调用子对象的方法
procedure B;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Taclass.iProc;
begin
ShowMessage('TaClass.iProc');
end;
procedure Taclass.A;
begin
ShowMessage('TaClass.A');
end;
procedure TbClass.iProc;
begin
// inherited;
ShowMessage('TbClass.iProc');
end;
procedure Tbclass.B;
begin
ShowMessage('TbClass.B');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
objA: TaClass;
objB: TbClass;
begin
ObjA := TbClass.create;
ObjA.iProc; //父对象调用子对象的方法
ObjA.Free;
objB := TBClass.create;
objB.iProc;
objB.Free;
end;