why aren't descendants of TInterfacedObject garbage collected?

后端 未结 3 554
臣服心动
臣服心动 2021-01-03 05:16

i have a class based on TInterfacedObject. i add it to TTreeNode\'s Data property.

TFacilityTreeItem=class(TInterfacedObject)
private
  m_guidItem:TGUID;
           


        
3条回答
  •  悲&欢浪女
    2021-01-03 05:59

    You should declare the Field/Variable as Interface

    IFacilityTreeItem = IInterface
    end;
    
    TFacilityTreeItem=class(TInterfacedObject, IFacilityTreeItem)
    private
      m_guidItem:TGUID;
      m_SomeOtherNode:TTreeNode;
    end;
    
    var
      Item: IFacilityTreeItem; // Variable as Interface
    begin
      Item:= TFacilityTreeItem.Create;
    ...
    end;
    

    To access your fields, you should declare properties in IFacilityTreeItem Interface, with Getters and Setters.

提交回复
热议问题