I must not understand unit references properly.
Take a look at Unit1 and Unit2 below:
unit Unit1;
uses Unit2;
Type
TMyDM = class(TDataModule)
//published stuff as usual
private
fWidget : TWidget;
procedure SetWidget(const Value: TWidget);
public
property ActiveWidget : TWidget read fWidget write SetWidget;
end;
Implementation
uses UnitB;
//implementation code here.
end.
var dm : TMyDM;
Then Unit2
unit Unit2;
Type
TWidget = class
//class declarations
public
Procedure SetAsActiveWidget;
end;
Implementation
uses Unit1;
procedure TWidget.SetAsActiveWidget;
begin
dm.ActiveWidget := Self;
end;
end.
It's the classic cyclical dependency mediated by use clauses in the declarative and implementation sections of each unit. Recently, I've introduced some changes and was stumped when the compiler returned the following error while compiling unit 2:
Identifier idents no member: "ActiveWidget"
Suddenly, the compiler could no longer see ActiveWidget in the scope of its compilation. I found this odd, as I had assumed the compiler would compile the definition sections of all units before moving on to the implementation side, but I may be mistaken.
Anyway, here's what blew me away: I moved the declaration of ActiveWidget in Unit1 to the top of TMyDM as follows:
unit Unit1;
uses Unit2;
Type
TMyDM = class(TDataModule)
private
fWidget : TWidget;
procedure SetWidget(const Value: TWidget);
public
property ActiveWidget : TWidget read fWidget write SetWidget;
published
//published stuff as usual
end;
Implementation
uses UnitB;
//implementation code here.
end.
var dm : TMyDM;
The program compiled without a hitch ...
Thought?