Delphi Error – E2060 Class and interface types only allowed in type section

Delphi Compiler Error

E2060 Class and interface types only allowed in type section

Reason for the Error & Solution

Class or interface types must always be declared with an explicit type declaration in a type section. Unlike record types, they cannot be anonymous.

The main reason for this is that there would be no way you could declare the methods of that type (since there is no type name).

Incorrect (attempting to declare a class type within a variable declaration):

program Produce;

var
  MyClass : class
    Field: Integer;
  end;

begin
end.

Correct:

program Solve;

type
  TMyClass = class
    Field: Integer;
  end;

var
  MyClass : TMyClass;

begin
end.

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...