相互使用的类的循环引用问题 [英] Circular reference issue with Classes which use each other

查看:146
本文介绍了相互使用的类的循环引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两个类:

TcmTPDataPanel = class(TcmTPBasePanel)
    Database: TnxDatabase;
    Session: TnxSession;
  private
    FDataConnector: TcmTPDataConnector;
    MyNxDataBase: TnxDatabase;
    MyNxSession: TnxSession;
    MyRefNxDataBase: TnxDatabase;
  protected
    procedure Disconnect; virtual; abstract;
    procedure Refresh; virtual;
    procedure Requery; virtual; abstract;
  public
    procedure Connect;
  published
    property DataConnector: TcmTPDataConnector read FDataConnector write
        FDataConnector;
  end;


TcmTPDataConnector = class(TComponent)
  private
    FDatabase: TnxDatabase;
    FObservers: TList;
    FTableForCategories: TnxTable;
    FTableForItemCategoryLinks: TnxTable;
    FTableForItems: TnxTable;
    procedure SetTableForItemCategoryLinks(const Value: TnxTable);
  protected
    procedure IterateObservers;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Register(Instance: TcmTPDataPanel);
    procedure Unregister(Instance: TcmTPDataPanel);
  published
    property Database: TnxDatabase read FDatabase write FDatabase;
    property TableForCategories: TnxTable read FTableForCategories write
        FTableForCategories;
    property TableForItemCategoryLinks: TnxTable read
        FTableForItemCategoryLinks write SetTableForItemCategoryLinks;
    property TableForItems: TnxTable read FTableForItems write FTableForItems;
  end;

TcmDataPanel是第3代TFrame后代。它不是直接使用,而是从中衍生出其他多种复合成分。

TcmDataPanel is a (3rd generation) TFrame descendent. It's not used directly, but rather multiple other compound components descend from it.

TcmDataConnector是一个组件,用于保存其他组件的数据库连接信息。

TcmDataConnector is a component which holds the database connection information for these other components.

我正在使用ModelMaker ,并尝试实现观察者模式,以便每当数据连接器更改状态时都可以自动更新多个数据面板。

I'm using ModelMaker, and am trying to implement an Observer pattern so that multiple "Data Panels" can be automatically updated whenever the "Data Connector" changes state.

这是我的问题:我可以似乎没有解决循环引用问题,因为每个类在接口部分中都使用另一个。将相关的用途引用放在界面部分中并不能解决未声明的标识符问题,而将二者都放在同一单元中也不会。现在它们位于同一单元中(我已经在单独的单元中并在一起尝试过),并且出现未声明的标识符:TcmTPDataConnector错误。

Here's my problem: I can't seem to get around the "circular refernece" problem, as each class uses the other in the Interface section. Putting the associated "uses" reference in the Interface section doesn't clear up the "Undeclared identifier" issue, and putting them both in the same unit doesn't either. Right now they are in the same unit (I've tried them in separate units, and together), and I get the "Undeclared identifier: TcmTPDataConnector" error.

如何解决这个问题?

============ ===

更新:

================
UPDATE:

今天星期五晚上9点30分,我被完全困住了。在我发帖仅几分钟后,大家就保存了这一天! (晚上!)谢谢!

It's Friday night at 9:30pm where I am, and I was totally stuck. Just MINUTES after my post, you people SAVED THE DAY!! (night!) THANK YOU!!

老兄,我喜欢StackOverflow ....所以我的朋友在这个学习狂的季节。 :)谢谢,谢谢,谢谢...

Man, I love StackOverflow.... SO my friend in this learning-like-crazy season. : ) Thank you, thank you, thank you...

推荐答案

在同一单元上,尝试以下操作:

On the same unit, try the following:

TcmTPDataConnector = class(TComponent);


TcmTPDataPanel = class(TcmTPBasePanel)
   ... 
end;

TcmTPDataConnector = class(TComponent)
  ...
end;

这篇关于相互使用的类的循环引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆