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.