2

I tried to construct a class system in Delphi. The classes TFieldSpec and TTableSpec refer to each other through object properties.

type
  TFieldSpec=class(Tobject)
  private
    FTableSpec : TTableSpec;
  public
    property TableSpec : TTableSpec read FTableSpec;
  end;

  TTableSpec=class(Tobject)
  private
    FFields : array[1..100] of TFieldSpec;
  end;

When I compile this, I get this error:

[Error] Objects.pas(66): Undeclared identifier: 'TTableSpec'

How to construct these class types?

NGLN
  • 43,011
  • 8
  • 105
  • 200
user1730626
  • 437
  • 1
  • 8
  • 16

1 Answers1

10

You should use forward declaration of TTableSpec:

type
  TTableSpec = class;

  TFieldSpec=class(Tobject)
  private
    ..
    FTableSpec : TTableSpec;
    ..
  end;

  TTableSpec=class(Tobject)
  private
    FName : string;
    ..
  end;
kludg
  • 27,213
  • 5
  • 67
  • 118