Delphi Error – E2358 Class constructors not allowed in class helpers

Delphi Compiler Error

E2358 Class constructors not allowed in class helpers

Reason for the Error & Solution

A class helper is a method extension for a given class. While you can use class constructors in the main body of your class, class constructors are forbidden to appear in class helpers. The reason is that a class constructor is added to the initialization section at compile time, when the compiler detects that the class is being used somewhere in the code. This cannot be done using class helpers.

Example:

{ Define a class }
TMyClass = class
  class constructor Create;                          // OK
end;

{ Define a class helper for the class }
TMyClassHelper = class helper for TMyClass
  procedure myBuilderMethod(AA:Integer; AB:Integer); // OK
  class constructor Create;                          // NOT OK
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...