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

前端之家收集整理的这篇文章主要介绍了delphi – 如何声明两个相互关联的类?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个类似于 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提供的资源中得到了一个现成的例子.

原文链接:https://www.f2er.com/delphi/103083.html

猜你在找的Delphi相关文章