06.Delphi接口的不对等的多重继承
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接口的不对等的多重继承的更多相关文章
- 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接口例子
- 05.Delphi接口的多重继承深入
由于是IInterface,申明了SayHello,需要由继承类来实现函数,相对于03篇可以再精简一下 unit uSayHello; interface uses SysUtils, Windows ...
- Delphi接口的底层实现(接口在内存中仍然有其布局,它依附在对象的内存空间中,有汇编解释)——接口的内存结构图,简单清楚,深刻 good
引言 接口是面向对象程序语言中一个很重要的元素,它被描述为一组服务的集合,对于客户端来说,我们关心的只是提供的服务,而不必关心服务是如何实现的:对于服务端的类来说,如果它想实现某种服务,实现与该服务相 ...
- 第06周-接口、内部类与Swing
1. 本周作业简评与建议 作业简评 Q1.覆盖clone需要:a.要implements标记接口 Cloneable接口.b.要区分浅拷贝与深拷贝.c.一般来说要调用super.clone,然后在此基 ...
- C#调用Delphi接口(ITest = interface)
首先创建一个delphi的DLL工程 library testintfdll; { Important note about DLL memory management: ShareMem must ...
- Delphi接口的底层实现
引言 接口是面向对象程序语言中一个很重要的元素,它被描述为一组服务的集合,对于客户端来说,我们关心的只是提供的服务,而不必关心服务是如何实现的:对于服务端的类来说,如果它想实现某种服务,实现与该服务相 ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:在 <tbody> 内的任一行启用鼠标悬停状态
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- mybatis 多参数传递
参考: 1. MyBatis传入多个参数的问题 http://www.cnblogs.com/mingyue1818/p/3714162.html2. MyBatis报错 Parameter '0' ...
- Elasticsearch 如何使用RESTful API
所有其他语言可以使用 RESTful API 通过端口 9200 和 Elasticsearch 进行通信,你可以用你最喜爱的 web 客户端访问 Elasticsearch .事实上,正如你所看到的 ...
- Go的WaitGroup
goroutine使用方便,但是如果不加以处理一般会deadlock,因为goroutine配合Chanel的话只能是一进一出,否则就会卡在那里.下面一个示例就是利用这个WaitGroup处理这种死锁 ...
- C++获取驱动盘句柄
转载:https://www.cnblogs.com/sherlock-merlin/p/10792116.html https://univasity.iteye.com/blog/8052 ...
- freemarker 作为 word 模板实现下载功能
1:新建一个.doc 文档写好自己要导出文字如下图 2:把word 文档另存为xml 格式的文件用编辑器打开如图下,(如果你打开文件里面的标签没换行格式,那么你在myeclipse 新建一个jsp 文 ...
- Linux centosVMware 自动化运维认识自动化运维、启动salt相关服务、saltstack配置认证、salt-key命令用法、saltstack远程执行命令、saltstack - grains、saltstack – pillar
一.认识自动化运维 传统运维效率低,大多工作人为完成 传统运维工作繁琐,容易出错 传统运维每日重复做相同的事情 传统运维没有标准化流程 传统运维的脚本繁多,不能方便管理 自动化运维就是要解决上面所有问 ...
- 转:Entity Framework 5.0 Code First全面学习
Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code Firs ...
- SpringBoot项目中自定义注解的使用
1.定义注解接口 @Documented @Retention(RUNTIME) @Target(METHOD) public @interface MyLog { String value() ...
- 3.Sprint 代理对象与原始对象的异常错误
代码案例分析 Service层添加了注解@Transactional @Service @Transactional public class CustomerService extends Base ...