1. 程式人生 > >Delphi 接口(5)-接口與類型轉換

Delphi 接口(5)-接口與類型轉換

RoCE pre test style imp interface pro clas bject

//接口與類型轉換

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;

Delphi 接口(5)-接口與類型轉換