uSayHello代码如下

unit uSayHello;

interface

uses
SysUtils,
Windows,
Messages,
Classes,
Graphics,
Controls,
Forms,
Dialogs; type
ISpeakChinese = interface(IInterface)
function SayHello: string;
end; ISpeakEnglish = 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
FSkinColor: string;
function SayHello: string;
public
constructor create;
property SkinColor: string read FSkinColor write FSkinColor;
end; TAmerican = class(TMan, ISpeakEnglish)
private
function SayHello: string;
end; TAmericanChinese = class(TChinese, ISpeakEnglish)
public
constructor create;
function TomSayHello: string;
end; implementation function TAmerican.SayHello: string;
begin
result := 'Hello!';
end; constructor TChinese.create;
begin
SkinColor := '黄色';
end; function TChinese.SayHello: string;
begin
result := '你好!';
end; constructor TAmericanChinese.create;
begin
name := 'Tom Wang';
Inherited;
end; function TAmericanChinese.TomSayHello: string;
var
// Dad: ISpeakChinese;
Mum: ISpeakEnglish;
begin
// Dad:=TChinese.Create;
// 只有子类TAmerican才具体实现了SayHello的方法
Mum := TAmerican.create;
// SayHello是继承的中国人的Hello方法
result := SayHello + Mum.SayHello;
end; end.

调用单元如下

unit frmMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
Button1: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation uses uSayHello; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
Tom:TAmericanChinese;
begin
Tom:=TAmericanChinese.Create;
try
LabeledEdit1.text:=Tom.Name;
LabeledEdit2.text:=Tom.SkinColor;
Showmessage(Tom.Tomsayhello);
finally
Tom.Free;
end;
end; end.

06.Delphi接口的不对等的多重继承的更多相关文章

  1. zw版_Halcon图像库delphi接口文件

    zw版_Halcon图像库delphi接口文件 Halcon图像库delphi接口文件,根据安装时用户设置的文件目录不同,会有所差异,笔者一般安装在delphi的import目录下.     参见:& ...

  2. delphi 接口Interface

    学习 delphi 接口 一切都是纸老虎!!! 第四章          接口 前不久,有位搞软件的朋友给我出了个谜语.谜面是“相亲”,让我猜一软件术语.我大约想了一分钟,猜 出谜底是“面向对象”.我 ...

  3. Delphi 接口使用中,对象生命周期管理,如何释放需要注意的问题

    网上有篇文章<Delphi接口编程的两大陷阱>,里面提到接口的生存期管理的问题.但该文章里面提到的两个问题,其实都是对 Delphi 不理解导致的.   先说该篇文章中提到的第一个问题为什 ...

  4. 微软手写识别模块sdk及delphi接口例子

    http://download.csdn.net/download/coolstar1204/2008061 微软手写识别模块sdk及delphi接口例子

  5. 05.Delphi接口的多重继承深入

    由于是IInterface,申明了SayHello,需要由继承类来实现函数,相对于03篇可以再精简一下 unit uSayHello; interface uses SysUtils, Windows ...

  6. Delphi接口的底层实现(接口在内存中仍然有其布局,它依附在对象的内存空间中,有汇编解释)——接口的内存结构图,简单清楚,深刻 good

    引言 接口是面向对象程序语言中一个很重要的元素,它被描述为一组服务的集合,对于客户端来说,我们关心的只是提供的服务,而不必关心服务是如何实现的:对于服务端的类来说,如果它想实现某种服务,实现与该服务相 ...

  7. 第06周-接口、内部类与Swing

    1. 本周作业简评与建议 作业简评 Q1.覆盖clone需要:a.要implements标记接口 Cloneable接口.b.要区分浅拷贝与深拷贝.c.一般来说要调用super.clone,然后在此基 ...

  8. C#调用Delphi接口(ITest = interface)

    首先创建一个delphi的DLL工程 library testintfdll; { Important note about DLL memory management: ShareMem must ...

  9. Delphi接口的底层实现

    引言 接口是面向对象程序语言中一个很重要的元素,它被描述为一组服务的集合,对于客户端来说,我们关心的只是提供的服务,而不必关心服务是如何实现的:对于服务端的类来说,如果它想实现某种服务,实现与该服务相 ...

随机推荐

  1. PAT A1091 Acute Stroke

    对于坐标平面的bfs模板题~ #include<bits/stdc++.h> using namespace std; ; ][][]={false}; ][][]; int n,m,l, ...

  2. nginx 的precontent阶段的ngx_http_try_files_module模块与mirrors模块介绍

    指令介绍 Syntax: try_files file ... uri; try_files file ... =code; Default: — Context: server, location ...

  3. c数据结构线性表的总结

    1:连表的特点   1.链表是一种存储结构,用于存放线性表   2.连表的结点是根据需要调用动态分配内存函数进行分配的,因此链表可随需要伸长缩短      在腰存储的数据个数未知的情况下节省内存.   ...

  4. IP show

    1. 查看本机公网IP 1.1 curl ifconfig.me 1.2 ipinfo.io 1.3 test-ipv6.com 1.4 more 2. 查看本机IP,host 2.1 hostnam ...

  5. node.js中的事件轮询Event Loop

    任务队列/事件队列 "任务队列"是一个事件的队列,IO设备完成一项任务,就在"任务队列"中添加一个事件,表示相关的异步任务可以进入"执行栈" ...

  6. pytorch张量数据索引切片与维度变换操作大全(非常全)

    (1-1)pytorch张量数据的索引与切片操作1.对于张量数据的索引操作主要有以下几种方式:a=torch.rand(4,3,28,28):DIM=4的张量数据a(1)a[:2]:取第一个维度的前2 ...

  7. 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件

    实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...

  8. 为Linux环境安装图形化界面

    1.更新软件源并升级系统 yum uppdate&&yum install wqy-microhei-fonts 2.安装GNOME+VNC一键包 wget https://gist. ...

  9. KDE Plasma 5.17 即将发布

    导读 Plasma 5.17上个月达到了beta版本,而下周将发布Plasma 5.17.0版本!KDE桌面的大更新只有几天了.因此,开发人员一直在整理它,同时也集思广益讨论Plasma 5.18应该 ...

  10. 【JS 常用操作】

    正则表达式 <script> var str = "(08:30-10:00)"; var patt = /^[(][0-9]{2}:[0-9]{2}-[0-9]{2} ...