7

これに似た質問がありますが、デルファイです。

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

type
  TAsyncPopulator = class
  private
    _updater: TThreadPopulator;
  end;

上記の質問の解決策は、デルファイには適用されません

4

3 に答える 3

13

Forward Declarations and Mutually Dependent Classesドキュメントを参照してください。

type (* start type section - one unified section "to rule them all" *)

  TAsyncPopulator = class; (* forward declaration, it basically serves just to
  fix SizeOf(TAsyncPopulator) so compiler would be able to draft dependent types'
  in-memory layout. Down the CPU level `class` and `pointer` is the same, so now 
  Delphi knows SizeOf(TAsyncPopulator) = SizeOf(pointer) to compose further types *)

  TThreadPopulator = class(TThread)
  private
    _owner:TASyncPopulator;
  end;
    
  TAsyncPopulator = class (* the final declaration now, it should go WITHIN 
  that very TYPE-section where the forward declaration was made! *)
  private
    _updater: TThreadPopulator;
  end;

  ....

type 
(* now, that you had BOTH forward and final declarations for TAsyncPopulator 
   spelled out above, you finally may start another TYPE-section, if you choose so. 
   But only after them both, and never should a new `type` section be inserted 
   in between those declarations. *)
  ....

ソースを使え、ルーク!Delphi インストールには、読み、見て、学ぶための完全な VCL および RTL ソースがあります。そして、このテンプレートをよく使用します。「どうすればそれができるのか」と自問するたびに、「Borland はどのようにそれを行ったのか」を考えるだけで、Delphi が提供するソースで既製の例をすでに入手できる可能性が高くなります。

于 2012-10-22T06:09:50.847 に答える
3

クラス定義の前にこれを使用します。フォワード クラスは Delphi 2010 で動作します。お持ちのデルファイのウィッチ バージョンはわかりませんが、考えられる唯一の解決策です。

type   
 TAsyncPopulator = Class;

私が助けてくれることを願っています

于 2012-10-22T06:07:08.743 に答える
1

前方宣言を使用する以外に、サブクラスを作成してこれを解決することもできます。

TThreadPopulator = class(TThread)
  type 
    TAsyncPopulator = class 
      _updater: TThreadPopulator;  
    end;

  var 
    owner: TAsyncPopulator;
end;
于 2013-03-04T23:47:41.410 に答える