E2205 Interface type required (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

A type, which is an interface, was expected but not found. A common cause of this error is the specification of a user-defined type that has not been declared as an interface type.


program Produce;
  type
    Name = string;

    MyObject = class
    end;

    MyInterface = interface(MyObject)
    end;

    Base = class(TObject, Name)
    end;

begin
end.

In this example, the type 'Base' is erroneously declared since 'Name' is not declared as an interface type. Likewise, 'MyInterface' is incorrectly declared because its ancestor interface was not declared as such.


program Solve;
  type
    BaseInterface = interface
    end;

    MyInterface = interface(BaseInterface)
    end;

    Base = class(TObject, MyInterface)
    end;

begin
end.

The best solution when encountering this error is to reexamine the source code to determine what was really intended. If a class is to implement an interface, it must first be explicitly derived from a base type such as TObject. When extended, interfaces can only have a single interface as its ancestor.

In the example above, the interface is properly derived from another interface and the object definition correctly specifies a base so that interfaces can be specified.