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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐