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