Delphi Error – E2059 Local class, interface or object types not allowed

Delphi Compiler Error

E2059 Local class, interface or object types not allowed

Reason for the Error & Solution

Class and object cannot be declared local to a procedure.

program Produce;

  procedure MyProc;
  type
    TMyClass = class
      Field: Integer;
    end;
  begin
  (*...*)
  end;

begin
end.

So MyProc tries to declare a class type locally, which is illegal.

program Solve;

  type
    TMyClass = class
      Field: Integer;
    end;

  procedure MyProc;
  begin
  (*...*)
  end;

begin
end.

The solution is to move out the declaration of the class or object type to the global scope.

Share:

Leave A Reply

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

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...