HomeDelphiDelphi Error – E2131 Class already has a default property

Delphi Error – E2131 Class already has a default property

Delphi Compiler Error

E2131 Class already has a default property

Reason for the Error & Solution

You have tried to assign a default property to a class which already has defined a default property.

program Produce;

  type
    Base = class
      function GetV(i : Integer) : Char;
      procedure SetV(i : Integer; const x : Char);

      property Data[i : Integer] : Char read GetV write SetV; default;
      property Access[i : Integer] : Char read GetV write SetV; default;
    end;

  function Base.GetV(i : Integer) : Char;
  begin GetV := 'A';
  end;

  procedure Base.SetV(i : Integer; const x : Char);
  begin
  end;

begin
end.

The Access property in the code above attempts to become the default property of the class, but Data has already been specified as the default. There can be only one default property in a class.

program Solve;

  type
    Base = class
      function GetV(i : Integer) : Char;
      procedure SetV(i : Integer; const x : Char);

      property Data[i : Integer] : Char read GetV write SetV; default;
    end;

  function Base.GetV(i : Integer) : Char;
  begin GetV := 'A';
  end;

  procedure Base.SetV(i : Integer; const x : Char);
  begin
  end;

begin
end.

The solution is to remove the incorrect default property specifications from the program source.

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