E2358 Class constructors not allowed in class helpers (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)


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;