Delphi的学习笔记十四——接口1

来源:互联网 发布:网络购物的发展现状 编辑:程序博客网 时间:2024/05/16 00:43

1.接口命名约定I起头,类是T起头的。

IMyInterface1 = Interface    function Func1:Integer;    function Func2:Integer; end;

2.接口都是从IInterfacej继承的,若是从根接口继承,则可省略

  {定义继承接口的类}  TMyClass = class(TInterfacedObject,IMyInterface1,IMyInterface2)  public    procedure Proc1;    procedure Proc2;    function Func1:Integer;    function Func2:Integer;  end;

3.接口成员只能是方法、属性,没有字段

4.接口成员都是公开的

5.接口只有声明,没有实现

6.接口只能从另一个接口继承,但不能从多个接口继承

7.一个类可以实现多个接口

8.实现接口的类一般继承于TInfacedObject

9.接口在用完后会自释放,并同时释放拥有它的类

10.接口的使用

procedure TForm2.Button2Click(Sender: TObject);var  i1:IMyInterface1;begin  i1:=TMyClass.create;  i1.Func1;  i1.Func2;end;