Delphi Error – E2174 ‘%s’ not previously declared as a PROPERTY

Delphi Compiler Error

E2174 ‘%s’ not previously declared as a PROPERTY

Reason for the Error & Solution

You have attempted to hoist a property to a different visibility level by redeclaration, but <name> in the base class was not declared as a property. -W

program Produce;
(*$WARNINGS ON*)

  type
    Base = class
    protected
      Caption : String;
      Title : String;
      property TitleProp : string read Title write Title;
    end;

    Derived = class (Base)
    public
      property Title read Caption write Caption;
    end;

begin
end.

The intent of the redeclaration of ‘Derived.Title’ is to change the field which is used to read and write the property ‘Title’ as well as hoist it to ‘public’ visibility. Unfortunately, the programmer really meant to use ‘TitleProp’, not ‘Title’.

program Solve;
(*$WARNINGS ON*)

  type
    Base = class
    protected
      Caption : String;
      Title : String;
      property TitleProp : string read Title write Title;
    end;

    Derived = class (Base)
    public
      property TitleProp read Caption write Caption;
      property Title : string read Caption write Caption;
    end;

begin
end.

There are a couple ways of approaching this error. The first, and probably the most commonly taken, is to specify the real property which is to be redeclared. The second, which can be seen in the redeclaration of ‘Title’ addresses the problem by explicitly creating a new property, with the same name as a field in the base class. This new property will hide the base field, which will no longer be accessible without a typecast. (Note: If you have warnings turned on, the redeclaration of ‘Title’ will issue a warning notifying you that the redeclaration will hide the base class’ member.)

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