加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何声明两个相互关联的类?

发布时间:2020-12-15 10:10:49 所属栏目:大数据 来源:网络整理
导读:我有一个类似于 this的问题,但是在delphi中. type TThreadPopulator = class(TThread) private _owner:TASyncPopulator; //Undeclared identifier end;type TAsyncPopulator = class private _updater: TThreadPopulator; end; 提到的问题的解决方案不适用于
我有一个类似于 this的问题,但是在delphi中.
type
  TThreadPopulator = class(TThread)
  private
    _owner:TASyncPopulator; //Undeclared identifier
  end;

type
  TAsyncPopulator = class
  private
    _updater: TThreadPopulator;
  end;

提到的问题的解决方案不适用于delphi

解决方法

请参见 Forward Declarations and Mutually Dependent Classes文档.
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提供的资源中得到了一个现成的例子.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读