Delphi Error – E2177 Constructors and destructors not allowed in OLE automation section

Delphi Compiler Error

E2177 Constructors and destructors not allowed in OLE automation section

Reason for the Error & Solution

You have incorrectly tried to put a constructor or destructor into the ‘automated’ section of a class declaration.

program Produce;

  type
    Base = class
    automated
      constructor HardHatBob;
      destructor  DemolitionBob;
    end;

  constructor Base.HardHatBob;
  begin
  end;

  destructor Base.DemolitionBob;
  begin
  end;

begin
end.

It is not possible to declare a class constructor or destruction in an OLE automation section. The constructor and destructor declarations in the above code will both elicit this error.

program Solve;

  type
    Base = class
      constructor HardHatBob;
      destructor  DemolitionBob;
    end;

  constructor Base.HardHatBob;
  begin
  end;

  destructor Base.DemolitionBob;
  begin
  end;

begin
end.

The only solution to this error is to move your declarations out of the automated section, as has been done in this example.

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