//接口与类型转换 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;
本文介绍了一种使用接口和类型转换的方法。定义了IFoot和IBall两个接口,并创建了一个TFootball类,该类实现了这两个接口。通过实例化TFootball类并将其转换为IFoot接口,展示了合法的类型转换过程。进一步地,文章演示了如何将IFoot类型的对象再转换为IBall类型。
3518

被折叠的 条评论
为什么被折叠?



