码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi 接口(6)-接口和多重继承

时间:2018-10-27 21:18:56      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:str   nbsp   imp   bubuko   nes   res   inf   read   inter   

技术分享图片

技术分享图片

unit uSayHello;

interface

uses    
    SysUtils,
    Windows,
    Messages,
    Greaphics,
    Controls,
    Forms,
    Dialogs;

type    
ISeakChinese = interface(IInterface)
    function SayHello: string;
end;

ISpeakEndlish = interface(IInterface)
    function SayHello: string;
end;

TMan = class(TInterfacedObject)
private
    FName: string;
public
    property Name: string read FName write FName;
end;

TChinese = class(TMan,ISpeakChinese)
private
    function SayHello: string;
end;

TAmerican = class(TMan,ISpeakEndlish)
    function SayHello: string;
end;

TAmericanChinese = class(TMan,ISpeakChinese,ISpeakEndlish)
public
    constructor create;
    function SayHello: string;
end;

implementation

function TAmerican.SayHello: string;
begin
  result := Hello!;
end;

function TChinese.SayHello: string;
begin
  result := 你好;
end;

function TAmericanChinese.create;
begin
  name := Tom Wang;
end;

function TAmericanChinese : string;
var
    Dad:ISpeakChinese;
    Mum:ISpeakEndlish;
begin
  Dad := TChinese.create;
  Mum := TAmerican.create;
  result := Dad.SayHello + Mum.SayHello;
end;

end.

 

Delphi 接口(6)-接口和多重继承

标签:str   nbsp   imp   bubuko   nes   res   inf   read   inter   

原文地址:https://www.cnblogs.com/YiShen/p/9863072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!