emailx45
Programmer
- Jan 10, 2025
- 6
Pay attention to usage of "USES" clausule:
Why does it happen?
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: