Delphi – E2062 Virtual constructors are not allowed 

In Delphi, Object types, unlike class types, can only have static constructors.

program Produce;

type
  TMyObject = object
    constructor Init; virtual;
  end;

constructor TMyObject.Init;
begin
end;

begin
end.

The example attempts to specify a virtual function Object() { [native code] }, which is not appropriate for object types and thus unlawful.

program Solve;

type
  TMyObject = object
    constructor Init;
  end;

constructor TMyObject.Init;
begin
end;

begin
end.

The solution is to either make the constructor static, or to use a new-style class type which can have a virtual constructor.

%d bloggers like this: