05.Delphi接口的多重继承深入
由于是IInterface,申明了SayHello,需要由继承类来实现函数,相对于03篇可以再精简一下
unit uSayHello; interface uses
SysUtils,
Windows,
Messages,
Classes,
Graphics,
Controls,
Forms,
Dialogs; type
// 说话类,由于是IInterface,申明了SayHello,需要由继承类来实现函数
ISpeakLanguage = interface(IInterface)
function SayHello: string;
end; ISpeakChinese = interface(ISpeakLanguage)
end; ISpeakEnglish = interface(ISpeakLanguage)
end; // TInterfacedObject相对于IInterface,添加了一些属性,更方便好用
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, ISpeakEnglish)
private
function SayHello: string;
end; TAmericanChinese = class(TMan, ISpeakChinese, ISpeakEnglish)
public
constructor create;
function SayHello: string;
end; implementation function TAmerican.SayHello: string;
begin
result := 'Hello!';
end; function TChinese.SayHello: string;
begin
result := '你好!';
end; constructor TAmericanChinese.create;
begin
name := 'Tom Wang';
end; // 继承中文和英文
function TAmericanChinese.SayHello: string;
var
Dad: ISpeakChinese;
Mum: ISpeakEnglish;
begin
Dad := TChinese.create;
Mum := TAmerican.create;
// 输出
result := Dad.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;
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;
// 输出
Showmessage(Tom.sayhello);
finally
Tom.Free;
end;
end; end.
05.Delphi接口的多重继承深入的更多相关文章
- zw版_Halcon图像库delphi接口文件
zw版_Halcon图像库delphi接口文件 Halcon图像库delphi接口文件,根据安装时用户设置的文件目录不同,会有所差异,笔者一般安装在delphi的import目录下. 参见:& ...
- delphi 接口Interface
学习 delphi 接口 一切都是纸老虎!!! 第四章 接口 前不久,有位搞软件的朋友给我出了个谜语.谜面是“相亲”,让我猜一软件术语.我大约想了一分钟,猜 出谜底是“面向对象”.我 ...
- Delphi 接口使用中,对象生命周期管理,如何释放需要注意的问题
网上有篇文章<Delphi接口编程的两大陷阱>,里面提到接口的生存期管理的问题.但该文章里面提到的两个问题,其实都是对 Delphi 不理解导致的. 先说该篇文章中提到的第一个问题为什 ...
- 微软手写识别模块sdk及delphi接口例子
http://download.csdn.net/download/coolstar1204/2008061 微软手写识别模块sdk及delphi接口例子
- 03.Delphi通过接口实现多重继承的优化
在上一篇02中,写到的sayhello函数,需要使用2个接口参数,很繁琐.可以使用as参数,把多重继承的子类对象变成需要的对象 uSayHello代码如下 unit uSayHello; interf ...
- 02.Delphi通过接口实现多重继承
uSayHello类如下: unit uSayHello; interface type // 接口 IGreetable = interface ['{D91DDE09-0FC4-4FE9-AE0D ...
- 06.Delphi接口的不对等的多重继承
uSayHello代码如下 unit uSayHello; interface uses SysUtils, Windows, Messages, Classes, Graphics, Control ...
- C++解析(24):抽象类和接口、多重继承
0.目录 1.抽象类和接口 1.1 抽象类 1.2 纯虚函数 1.3 接口 2.被遗弃的多重继承 2.1 C++中的多重继承 2.2 多重继承的问题一 2.3 多重继承的问题二 2.4 多重继承的问题 ...
- java中接口与多重继承的关系
在Java语言中, abstract class 和interface 是支持抽象类定义的两种机制.正是由于这两种机制的存在,才赋予了Java强大的 面向对象能力.abstract class和int ...
随机推荐
- Mybatis的三种批量操作数据的方法
方法1: 使用for循环在java代码中insert (不推荐) 方法2: 使用 在Mapper.xml当中使用 foreach循环的方式进行insert PersonDao.java文件 publi ...
- jdk动态代理和cglib动态代理底层实现原理超详细解析(jdk动态代理篇)
代理模式是一种很常见的模式,本文主要分析jdk动态代理的过程 1.举例 public class ProxyFactory implements InvocationHandler { private ...
- Java 自定义DateUtils
1 /* Date d = new Date(); String s = DateUtils.DateToString(d, "yyyy-MM-dd HH:mm:ss"); Sys ...
- Linux创建智能DNS
根据客户端源IP地址的不同,DNS服务提供不同的解析地址 1.安装dns服务,修改全局配置文件/etc/named.conf # yum -y install bind # vim /etc/name ...
- ash.jpg
- Outlook 2013 您的组织策略阻止我们为您完成此操作... 解决方法
问题:点击outlook超链接,弹出“您的组织策略阻止我们为您完成此操作”的提示,无法打开链接. 环境 OS: Win10 专业版x64bit Outlook: 2013 浏览器:搜狗浏览器 解决办法 ...
- hbase meta中分区信息错误的记录
bulk write hbase 时遇到下面的错误: 19/03/20 02:16:02 ERROR LoadIncrementalHFiles: IOException during splitti ...
- Tomcat的部署、虚拟主机及优化
Tomcat的部署.虚拟主机及优化 文章目录 Tomcat的部署.虚拟主机及优化 前言 1.Tomcat的名称由来 2.Apache Tomcat 5-7版本差异 2.1Apache Tomcat5. ...
- UIWindow的获取
注意:还是直接用下面这个比较靠谱.尤其是iOS11之后. [UIApplication sharedApplication].keyWindow; 1.下面这种是比较严谨的方式 - (UIWind ...
- 组件公用数据 Vue.observable( )
注意(适合小项目,不用vuex的情况下使用) 1.创建store.js 最好和main.js平级创建文件 import Vue from 'vue' export const store = Vue. ...