- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设您有以下内容:
//Note the original example I posted didn't reproduce the problem so
//I created an clean example
type
IParent = interface(IInterface)
['{85A340FA-D5E5-4F37-ABDD-A75A7B3B494C}']
procedure DoSomething;
end;
IChild = interface(IParent)
['{15927C56-8CDA-4122-8ECB-920948027015}']
procedure DoSomethingElse;
end;
TGrandParent = class(TInterfacedObject)
end;
TParent = class(TGrandParent)
end;
TChild = class(TParent, IChild)
private
FChildDelegate: IChild;
public
property ChildDelegate:IChild read FChildDelegate implements IChild;
end;
TChildDelegate = class(TInterfacedObject, IChild)
public
procedure DoSomething;
procedure DoSomethingElse;
end;
我认为这将允许您调用 DoSomething
但事实似乎并非如此:
procedure CallDoSomething(Parent: TParent);
begin
if Parent is TChild then
TChild(Parent).DoSomething;
end;
很明显,编译器正在强制执行接口(interface)继承,因为除非实现了 IParent
的成员,否则两个类都不会编译。尽管如此,当实例化和使用该类时,编译器仍无法解析 IParent
的成员。
我可以通过在类声明中显式包含 IParent
来解决此问题TMyClass
:
TMyClass = class(TInterfacedObject, IChild, IParent)
没关系,这解决不了任何问题。
最佳答案
如果一个实现类没有声明它支持继承接口(interface),那么该类将不会与继承接口(interface)的变量兼容赋值。您发布的代码示例应该可以正常工作(使用 IChild 接口(interface)),但是如果您尝试从 TMyClass 的实例分配给 IParent 的变量,那么您就会遇到麻烦。
原因是 COM 和 ActiveX 允许实现实现后代接口(interface)(您的 IChild),但拒绝该接口(interface)的祖先(IParent)。由于 Delphi 接口(interface)旨在与 COM 兼容,因此这就是这个愚蠢的工件的来源。
我很确定我在大约 10 或 12 年前写过一篇关于此问题的文章,但我的 Borland 博客在过渡到 Embarcadero 服务器后未能幸存。
可能有一个编译器指令可以更改此行为,我不记得了。
关于Delphi接口(interface)继承: Why can't I access ancestor interface's members?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380002/
我正在尝试为先决条件单元创建一个祖先表。我不确定如何使用 SQL 脚本为 2 级、3 级等插入数据... 我有三个表: Unit_Of_Competency(Unit_Of_Competency_ID
我想渲染一个源代码为 Github 的 iframe,如下所示: 这是我在控制台中遇到的错误: Refused to display 'https://gist.github.com/fresh5
我试图在我制作的两个组件之间共享状态。根据我的研究,我相信我需要将状态提升到祖先组件,然后将该状态向下传递到其他组件。作为引用,我添加了一个文件上传器,它将接收一个 json 文件,然后我将通过 js
我正在尝试找到一种方法来将这种转换重新处理到不必在Xpath中使用ancestor::轴的位置: 来源示例:
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
我有一个应用程序 siteA.com,它加载到 siteB.com 内的 iframe 中。直接加载 siteA.com 时没有警告,但在 siteB.com 的 iframe 内时得到 Unreco
什么定义了祖先?更具体地说,E 会是 H 的祖先吗?或者更简单地说,F、C、A 是 H 的祖先?甚至G?我只想澄清这个简单的概念。 最佳答案 E 不是 H 的祖先。它是 叔叔因为它是 兄弟 F,即 家
查找类为“bar”的div,其祖先在顶级“foo”的范围内不具有类“foo”。例如, 查找不在嵌套“f
我在切换汉堡包下拉菜单时遇到问题。基本上我在容器中有汉堡包图标,但导航列表在曾祖父 div 中,我不知道如何使用 JQuery 从较低的祖先 div 中切换导航列表的显示。 编辑: 忘记指定我想在可能
我最近接受了一次电话采访。它涉及将问题编码作为过程的一部分。 问题是 Find the most closest common ancestor of a tree 的变体,但有一个扭曲。这棵树很像图
我们要遍历节点的祖先,直到找到具有特定类的父节点。 SpriteKit 允许您使用 children 属性遍历子级,但 parent 属性只包含直接父级——而不是父级数组。我们如何遍历一个节点的所有祖
我希望使用 git-rev-parse 的指定修订部分中显示的 parent^ 和 ancestor generation~ 格式来描述相对于更新标记的特定提交。 是否有获取此格式的简单命令? 最佳答
XPath 2.0 中的 preceding:: 和 ancestor:: 有什么区别? 最佳答案 preceding:: 轴包含文档中之前该节点的所有节点,不包括该节点的祖先,它们位于 ancest
我想知道在 git merge 冲突解决期间“共同祖先”提交的身份。 换种说法:我想知道 修订版的哈希值,当我在 git merge 期间解决冲突时,BASE 版本是从 中提取的。 希望有一个命令可以
我正在寻找用来描述继承祖先的 child 的最佳术语。 例如,“汽车”对象可能源自其祖先“车辆”。但是,有没有比导数更好/更合适的词来用于逆的导数? 最佳答案 当所讨论的项目之间可能存在中间层时,祖先
我正在使用graft命令将4个变更集从BranchA拉入BranchB。当我这样做时,有些被嫁接了,而有些则没有: PS D:\Dev\ProjectAlpha> hg graft 5f403abb2
我正在学习 Google Cloud Datastore GQL grammar - 特别是 HAS ANCESTOR和 HAS DESCENDANT比较运算符。 提供以下 Person 实体: 艾米
我将iFrame嵌入网页中,如下所示: var iframeProps = { 'data-type': self.props.type, allowTranspare
我有一些从 TMyForm 继承的表单(TMyForm 是具有源代码表单的第 3 方组件)。 当我在 IDE 中打开从 TMyForm 继承的表单时,我有: Error creating form:
我有一个部署脚本,该脚本将生成新镜像,停止具有相同镜像名称的现有容器,然后从这些镜像启动新容器。 我在这里使用答案按图像名称停止容器:Stopping docker containers by ima
我是一名优秀的程序员,十分优秀!