Delphi Error – E2178 Dynamic methods and message handlers not allowed in OLE automation section

Delphi Compiler Error

E2178 Dynamic methods and message handlers not allowed in OLE automation section

Reason for the Error & Solution

You have incorrectly put a dynamic or message method into an ‘automated’ section of a class declaration.

program Produce;

  type
    Base = class
    automated
      procedure DynaMethod; dynamic;
      procedure MessageMethod(VAR msg : Integer); message 151;
    end;

    procedure Base.DynaMethod;
    begin
    end;

    procedure Base.MessageMethod;
    begin
    end;

begin
end.

It is not possible to have a dynamic or message method declaration in an OLE automation section of a class. As such, the two method declarations in the above program both produce errors.

program Solve;

  type
    Base = class
      procedure DynaMethod; dynamic;
      procedure MessageMethod(VAR msg : Integer); message 151;
    end;

    procedure Base.DynaMethod;
    begin
    end;

    procedure Base.MessageMethod;
    begin
    end;

begin
end.

There are several ways to remove this error from your program. First, you could move any declaration which produces this error out of the automated section, as has been done in this example. Alternatively, you could remove the dynamic or message attributes of the method; of course, removing these attributes will not provide you with the desired behavior, but it will remove the error.

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