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