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接口的底层实现
引言 接口是面向对象程序语言中一个很重要的元素,它被描述为一组服务的集合,对于客户端来说,我们关心的只是提供的服务,而不必关心服务是如何实现的:对于服务端的类来说,如果它想实现某种服务,实现与该服务相 ...
随机推荐
- hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...
- Python 正则表达式之 sub 和 subn函数的使用
re.sub() 函数的功能 re是reguler expressioin的缩写,表示正则表达式 sub 是 substitute 的缩写,表示替换: re.sub是个正则表达式方面的函数,用来实现通 ...
- Vue——解决报错 Computed property "****" was assigned to but it has no setter.
在最近的项目中遇到了如下的警告信息: [Vue warn]: Computed property " currentStep" was assigned to but it has ...
- shell脚本中执行shell脚本
1.a.sh #!/bin/sh name="hello" ./b.sh $name 2.b.sh(这里把b.sh与a.sh放在同一目录下,便于演示) #!/bin/sh ech ...
- Codeforces 601A:The Two Routes 宽搜最短路径
A. The Two Routes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 「NOIP2009」Hankson的趣味题
题目描述 (由于本题是数论题,所以我只把题目大意说一下...) 输入时给定\(a_0,a_1,b_0,b_1\),题目要求你求出满足如下条件的\(x\)的个数: \[\begin{cases}\gcd ...
- 分段控制器UISegmentedControl的使用、同一个控制器中实现多个View的切换、addChildViewController等方法的使用
本文先讲解简单的分段控制器UISegmentedControl的使用,然后具体讲解它最常使用的场景:同一个控制器中实现多个View的切换. 文章构思: 1.先直接讲解一张UI效果图的四种实现方式. 2 ...
- Jenkins安装 maven插件
Maven Artifact ChoiceListProvider (Nexus)Maven Metadata Plugin for Jenkins CI serverMaven Release Pl ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:pig简介
实验目的 了解pig的该概念和原理 了解pig的思想和用途 了解pig与hadoop的关系 实验原理 1.Pig 相比Java的MapReduce API,Pig为大型数据集的处理提供了更高层次的抽象 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:表示一个危险动作的按钮操作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...