Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to avoid "References Circular" in your code... NOT EXPLICITLY (my way ) >:)

emailx45

Programmer
Jan 10, 2025
6
Pay attention to usage of "USES" clausule:

Code:
unit Unit1;

interface // < ---- WARNING

uses
  Unit3;   //  Unit1 uses Unit3 --> Unit3 uses Unit2  --> Unit2 uses Unit1

type
  TForm1 = class(TForm)
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//uses
//  Unit3;  // <---- OK

end.

Code:
unit Unit2;

interface  // < ---- WARNING

uses
  Unit1;   // Unit1 uses Unit3 --> Unit3 uses Unit2  --> Unit2 uses Unit1 <---- Will NOT COMPILE

implementation

//uses
//  Unit1;   <---- OK

end.

Code:
unit Unit3;

interface // < ---- WARNING

uses
  Unit2;   //  Unit1 uses Unit3 --> Unit3 uses Unit2  --> Unit2 uses Unit1

implementation

// uses
//  Unit2;   <---- OK

end.

Why does it happen?
  • The "Interface Section" is the part of the code that is exported to the outside world of the unit, thus, data conflicts occur in the act of compilation, preventing it from being completed.
  • The "Implementation section", on the other hand, is like a "black box" of all code/classes. Thus, they are not revealed to the outside world, nor are they (or should be) known by the client code that uses them.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top