A type cannot be used before it is declared (in terms of line numbers). In particular, this means that you cannot use a type declared in the implementation
section in the interface
section.
However, consider the following example:
unit VisibilityTest;
interface
type
TFrog = class
strict private type
TFrogMetabolism = class
procedure DoAnabolismStuff;
procedure DoCatabolismStuff;
end;
strict private
FMetabolism: TFrogMetabolism;
public
procedure Croak;
procedure Walk;
procedure Jump;
end;
implementation
{ TFrog.TFrogMetabolism }
procedure TFrog.TFrogMetabolism.DoAnabolismStuff;
begin
end;
procedure TFrog.TFrogMetabolism.DoCatabolismStuff;
begin
end;
{ TFrog }
procedure TFrog.Jump;
begin
end;
procedure TFrog.Croak;
begin
end;
procedure TFrog.Walk;
begin
end;
end.
Here the TFrog
class is visible to other units, as well as its Croak
, Walk
, and Jump
methods.
And it does have a (strict private
in this example) field of type TFrogMetabolism
, a type which can only be used inside TFrog
-- and therefore only inside this unit -- because of the preceding strict private
specification.
This should give you some ideas. A few variants are possible:
If you remove strict
from strict private type
, the TFrogMetabolism
class can be used everywhere inside this particular unit, and not only in TFrog
.
If you replace private
with protected
, the class can also be used in classes that aren't TFrog
but are derived from TFrog
.
TA
need a field that refers to a type that hasn't been defined yet? What is the goal here?