昨天在书上看到这么一段代码 对象myobject在申明的时候是属于父(TFATHER)类的 但是在构造的时候却构造成子(TSON)类,这样对吗?Type
TFatheer =Class
i:Integer;
End;
TSon =Class(TFather)
i:string;
End;
VAR
Myobject : TFather;
begin
Myonject :=TSon.Creat;
Myobject.i:='hello';//错误
TSon(Myobject).i:='hello';//正常
TFatheer =Class
i:Integer;
End;
TSon =Class(TFather)
i:string;
End;
VAR
Myobject : TFather;
begin
Myonject :=TSon.Creat;
Myobject.i:='hello';//错误
TSon(Myobject).i:='hello';//正常
因为TFather虽然为父类,但是他们都继承自TObject,当然了,TObject是有Create的方法的