什么是“循环继承"?在德尔福打过电话吗? [英] What is this "cyclic inheritance" called in Delphi?

查看:132
本文介绍了什么是“循环继承"?在德尔福打过电话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前几天我看到了这样的代码:

I saw a code like this the other day:

type
    TFather = class;
    TSon = class(TFather);
    TFather = class(TSon);
end;

儿子继承自父亲,儿子继承自儿子. 搜索循环继承,但仅搜索Java结果.

Son inherited from Father that inherited from Son. Searched for Cyclic Inheritance but only Java results.

这叫什么?

推荐答案

示例代码(现已被删除)无法实现您认为的功能.您会看到TMycxGridDBTableView被定义为TcxGridDBTableView的后代,然后您会看到TcxGridDBTableView被定义为TcxGridDBTableView的后代.

The example code (that's now been deleted) doesn't do what you think it does. You see TMycxGridDBTableView being defined as a descendant of TcxGridDBTableView, and then you see TcxGridDBTableView, defined as a descendant of TcxGridDBTableView.

但是,您在顶部看到的TcxGridDBTableView与您以后看到的TcxGridDBTableView不同.第一个引用在其他单元中在其他地方声明的类.下一次出现是在 this 单元中声明一个 new 类,该类恰好具有与另一个单元的类相同的基本名称.

However, the TcxGridDBTableView you see at the top is not the same TcxGridDBTableView that you see later. The first one refers to a class declared elsewhere, in some other unit. The next occurrence is declaring a new class in this unit that happens to have the same base name as the other unit's class.

该技术被称为插入器类.它用于引入新的GetViewDataClass方法,但最终仍具有相同的类名.使用具有该名称的控件的表单将使用该类的新版本,而不是原始版本.这是自定义VCL控件的一种方法,而无需编译和安装自定义程序包.

This technique is known as an interposer class. It's used to introduce a new GetViewDataClass method, but still end up with the same class name. The form that uses controls with that name will use the new version of the class instead of the original version. It's a way to customize a VCL control without having to compile and install a custom package.

这篇关于什么是“循环继承"?在德尔福打过电话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆