您的位置:首页 > 编程语言 > Delphi

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

2013-01-05 10:37 204 查看
接口的属性

1.接口属性的定义

{此接口声明了一个 Name 属性; 因为接口没有字段, read/write 都只能从方法}
  IMyInterface = interface
    function GetName:string;
    procedure SetName(val:string);
    property name:string read GetName write SetName;
  end;


2.接口属性的实现。通过声明实现接口的类中的字段来存取属性的值

{类实现的是接口的读写方法, 属性还是属于接口的; 类可以提供一个储存属性的字段}
  TMyClass = class(TInterfacedObject,IMyInterface)
  private
    FName : string;
  public
    function GetName: string;
    procedure SetName(val: string);
  end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: