delphi - Circular reference between class -
i need develop next diagram class:
wrote code, but, have problems of circular unit reference.
the xmlfilemanager class contains:
unit xmlfilemanager; interface uses xmldom, xmlintf, msxmldom, xmldoc, sysutils, dateutils, classes, dialogs, xmlenpmanager; type txmlfilemanager = class private [...] xmenp: txmlenpmanager; xmenpinicial: txmlenpmanager; xmenpfinal: txmlenpmanager; [...] end.
the abstract class, xmlnodemanager:
unit xmlnodemanager; interface uses xmldom, xmlintf, msxmldom, xmldoc, sysutils, dateutils, classes, dialogs, xmlfilemanager; type txmlnodemanager = class protected { sgy alias para strategy } sgyiterator: integer; sgycontext: txmlfilemanager; sgyattributes: tstringlist; sgynode: ixmlnode; [...] end.
and xmlenpmanager concrete class:
unit xmlenpmanager; interface uses xmldom, xmlintf, msxmldom, xmldoc, sysutils, dateutils, classes, dialogs, xmlnodemanager; type txmlenpmanager = class (txmlnodemanager) public constructor create(acontext: txmlfilemanager); overload; override; constructor createinicial(acontext: txmlfilemanager); reintroduce; overload; constructor createfinal(acontext: txmlfilemanager); reintroduce; overload; [...] end.
the builds fails error:
[dcc32 fatal error] xmlnodemanager.pas(7): f2047 circular unit reference 'xmlfilemanager'
any ideas how solve problem ?.
put txmlfilemanager
, txmlnodemanager
in both same unit
, same type
section, make sure type
section starts class forward: txmlnodemanager = class;
see official documentation: forward declarations , mutually dependent classes.
unit xmlfilemanagerandxmlnodemanager; interface uses xmldom, xmlintf, msxmldom, xmldoc, sysutils, dateutils, classes, dialogs, [...] type txmlnodemanager = class; txmlfilemanager = class private [...] xmenp: txmlenpmanager; xmenpinicial: txmlenpmanager; xmenpfinal: txmlenpmanager; [...] txmlnodemanager = class protected sgyiterator: integer; sgycontext: txmlfilemanager; sgyattributes: tstringlist; sgynode: ixmlnode; [...] end.
Comments
Post a Comment