RAD Studio Athens

E2140

Go Up to Error and Warning Messages (Delphi)

You have specified an index for a dynamic method which is already used by another dynamic method.


program Produce;

  type
    Base = class
      procedure First(VAR xย : Integer); message 151;
      procedure Second(VAR xย : Integer); message 151;
    end;

  procedure Base.First(VAR xย : Integer);
  begin
  end;

  procedure Base.Second(VAR xย : Integer);
  begin
  end;

begin
end.

The declaration of 'Second' attempts to reuse the same message index which is used by 'First'; this is illegal.


program Solve;

  type
    Base = class
      procedure First(VAR xย : Integer); message 151;
      procedure Second(VAR xย : Integer); message 152; (*change to unique index*)
    end;

    Derived = class (Base)
      procedure First(VAR xย : Integer); override; (*override base class behavior*)
    end;

  procedure Base.First(VAR xย : Integer);
  begin
  end;

  procedure Base.Second(VAR xย : Integer);
  begin
  end;

  procedure Derived.First(VAR xย : Integer);
  begin
  end;

begin
end.

There are two straightforward solutions to this problem. First, if you really do not need to use the same message value, you can change the message number to be unique. Alternatively, you could derive a new class from the base and override the behavior of the message handler declared in the base class. Both options are shown in the above example.