Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Using interfaces from another unit

Tags:

delphi

I am constantly getting the: Undeclared identifier for an interface type I have defined in another unit. Here is what I have:

unit Drawers;

interface

implementation

type

  IDrawer = interface
  ['{070B4742-89C6-4A69-80E2-9441F170F876}']
    procedure Draw();
  end;

end.

unit Field;

interface

uses
  Graphics, Classes, Drawers;

TField = class(TInterfacedObject, IField)
private
  FSymbolDrawer: IDrawer;

At FSymbolDrawer I get the complier error.

Of course I have the uses Drawers; in the unit where TField is defined.

What's this about?

Thank you

like image 634
elector Avatar asked Feb 17 '26 07:02

elector


1 Answers

In the unit Drawers the type declaration of IDrawer has to be in the interface part of the unit. You have inserted it in the implementation part where it is only visible for in-unit declarations.

Here is the code:

unit Drawers;

interface

type

  IDrawer = interface
  ['{070B4742-89C6-4A69-80E2-9441F170F876}']
    procedure Draw();
  end;

implementation

end.
like image 140
Matthias Alleweldt Avatar answered Feb 18 '26 22:02

Matthias Alleweldt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!