How to define a Type A in Type B and Type B in Type A?

后端 未结 3 1305
抹茶落季
抹茶落季 2021-01-18 03:34

I have two types. One Type A and one Type B. The Problem Type A contains Type B and Type B contains Type A. Such a thing like this won\'t work:

  type
    ty         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 04:28

    Perhaps the best solution is to rethink the design. But you might also be interested in so-called forward declarations of classes:

    type
      TTypeB = class;
    
      TTypeA = class
        test: TTypeB;
      end;
    
      TTypeB = class
        test: TTypeA;
      end;      
    

    SIC! This only works for classes, not records.

提交回复
热议问题