Delphi Error – E2209 Field declarations not allowed in interface type

Delphi Compiler Error

E2209 Field declarations not allowed in interface type

Reason for the Error & Solution

An interface has been encountered which contains definitions of fields; this is not permitted.

program Produce;
  type
    IBaseIntf = interface
      FVar : Integer;
      property Value : Integer read FVar write FVar;
    end;

begin
end.

The desire above is to have a property which has a value associated with it. However, as interfaces can have no fields, this idea will not work.

program Solve;
    IBaseIntf = interface
      function Reader : Integer;
      procedure Writer(a : Integer);
      property Value : Integer read Reader write Writer;
    end;

begin
end.

An elegant solution to the problem described above is to declare getter and setter procedures for the property. In this situation, any class implementing the interface must provide a method which will be used to access the data of the class.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...