如何声明两个相互关联的类? [英] How to declare two inter-linked classes?

查看:30
本文介绍了如何声明两个相互关联的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于this的问题,但在delphi中.

I have a question similar to this, but in delphi.

type
  TThreadPopulator = class(TThread)
  private
    _owner:TASyncPopulator; //Undeclared identifier
  end;

type
  TAsyncPopulator = class
  private
    _updater: TThreadPopulator;
  end;

上述问题的解决方案不适用于delphi

Solution of mentioned question is not applicable to delphi

推荐答案

参见 前向声明和相互依赖的类 文档.

See Forward Declarations and Mutually Dependent Classes documentation.

type (* start type section - one unified section "to rule them all" *)
  TAsyncPopulator = class; (* forward declaration *)

  TThreadPopulator = class(TThread)
  private
    _owner:TASyncPopulator;
  end;

  TAsyncPopulator = class (* final declaration - WITHIN that very section where forward declaration was made *)
  private
    _updater: TThreadPopulator;
  end;

使用来源,卢克!您的 Delphi 安装有完整的 VCL 和 RTL 源供您阅读、观看和学习.它经常使用这个模板.每次当您问自己我是怎么做到的"时,只要想一想Borland 是怎么做到的",并且很有可能您已经在 Delphi 提供的资源中获得了现成的示例.

Use the source, Luke! Your Delphi installation has full VCL and RTL sources for you to read and watch and learn. And it uses this template a lot. Every time when you ask yourself "how I could do it", just think along "how did Borland do it" and pretty chance that you can already get a ready-made example in Delphi-provided sources.

这篇关于如何声明两个相互关联的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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