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

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