Are circular unit references in the uses list possible in delphi?
This is a small example.
The actual header files are more complicated :\==File1.h==
struct a
{
int data;
}
int compare(struct a,struct b);
==File2.h==
struct b
{
int data;
}
int compare(struct A,struct b);
==File1.pas==
uses File2;
type
a = packed record
data: Integer;
end;
compare = function(d1: a; d2: b): Integer; cdecl;
==File2.pas==
uses File1;
type
b = packed record
data: Integer;
end;
compare = function(d1: a; d2: b): Integer; cdecl;
As Eugene points out circular interface unit references are not possible in Delphi. There are a few possible solutions:
- Move the shared struct to a third unit and let the other two units include this unit.
- Move one of the unit references to the
implementation
section (if this is possible). - Keep all in one file as you mention
Note that the fact that Delphi forces you to think about circular references is not a bad thing IMHO. In many cases, these circular references draw your attention to a flaw in your design.
Yes, you can't make the units reference each other in "interface" section. Move "uses" clause of one file to implementation section. This is a limitation of pascal.
精彩评论