Delphi Error – E2148 Dynamic method or message handler not allowed here

Delphi Compiler Error

E2148 Dynamic method or message handler not allowed here

Reason for the Error & Solution

Dynamic and message methods cannot be used as accessor functions for properties.

program Produce;

  type
    Base = class
      v : Integer;
      procedure SetV(x : Integer); dynamic;
      function GetV : Integer; message;
      property Velocity : Integer read GetV write v;
      property Value : Integer read v write SetV;
    end;

  procedure Base.SetV(x : Integer);
  begin v := x;
  end;

  function Base.GetV : Integer;
  begin GetV := v;
  end;

begin
end.

Both ‘Velocity’ and ‘Value’ above are in error since they both have illegal accessor functions assigned to them.

program Solve;

  type
    Base = class
      v : Integer;
      procedure SetV(x : Integer);
      function GetV : Integer;
      property Velocity : Integer read GetV write v;
      property Value : Integer read v write SetV;
    end;

  procedure Base.SetV(x : Integer);
  begin v := x;
  end;

  function Base.GetV : Integer;
  begin GetV := v;
  end;

begin
end.

The solution taken in this is example was to remove the offending compiler directives from the procedure declarations; this may not be the right solution for you. You may have to closely examine the logic of your program to determine how best to provide accessor functions for your properties.

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