RAD Studio (Common)
ContentsIndex
PreviousUpNext
E2059: Local class, interface or object types not allowed (Delphi)

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.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!