Delphi 接口(5)-接口与类型转换

//接口与类型转换

type
IFoot: interface
['|0000-0000-0000-0000|']
end;

IBall = interface
['|0000-0000-0000-0001|']
end;

TFootball = calss(TinterfacedObject,IFoot,IBall)
end;

implementation

procedure Test(FB: TFootball)
var 
    F:IFoot
begin
  F := FB;//合法,因为FB支持IFoot
end;

var
    FB: TFootball;
    F: IFoot;
    B: IBall;
begin
  FB := TFootBall.Create;
  F := FB;//合法,因为FB支持IFoot
  B := F as IBall;//把F(IFoot)转为IBall
end;

猜你喜欢

转载自www.cnblogs.com/YiShen/p/9863007.html