Delphi Error – E2122 PROCEDURE or FUNCTION expected

Delphi Compiler Error

E2122 PROCEDURE or FUNCTION expected

Reason for the Error & Solution

This error message is produced by two different constructs, but in both cases the compiler is expecting to find the keyword ‘procedure’ or the keyword ‘function’.

program Produce;

  type
    Base = class
      class AProcedure; (*case 1*)
    end;

  class Base.AProcedure; (*case 2*)
  begin
  end;

begin
end.

In both cases above, the word ‘procedure’ should follow the keyword ‘class’.

program Solve;

  type
    Base = class
      class procedure AProcedure;
    end;

  class procedure Base.AProcedure;
  begin
  end;

begin
end.

As can be seen, adding the keyword ‘procedure’ removes the error from this program.

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