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.