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

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

问题描述

我有一个类似于这个的问题,但在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;

使用源代码,Luke!您的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天全站免登陆