Delphi Error – F2047 Circular unit reference to ‘%s’

Delphi Compiler Error

F2047 Circular unit reference to ‘%s’

Reason for the Error & Solution

One or more units use each other in their interface parts.

As the compiler has to translate the interface part of a unit before any other unit can use it, the compiler must be able to find a compilation order for the interface parts of the units.

Check whether all the units in the uses clauses are really necessary, and whether some can be moved to the implementation part of a unit instead.

unit A;
interface
uses B;           (*A uses B, and B uses A*)
implementation
end.

unit B;
interface
uses A;
implementation
end.

The problem is caused because A and B use each other in their interface sections.

unit A;
interface
uses B;          (*Compilation order: B.interface, A, B.implementation*)
implementation
end.

unit B;
interface
implementation
uses A;          (*Moved to the implementation part*)
end.

Note: This can be fixed in one of two ways:

  • You can put the mutually referring classes inside the same unit and use forward declarations to resolve the problems.
  • Change the conflicting type to a more general type such as TObject or Pointer and use type casts to the previous type that caused the conflict (this can only be done in the case where the type is used internally.)

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...