E2147 Property '%s' does not exist in base class (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

The compiler believes you are attempting to hoist a property to a different visibility level in a derived class, but the specified property does not exist in the base class.


program Produce;

  type
    Base = class
    private
      a : Integer;
      property BaseProp : integer read a write a;
    end;

    Derived = class (Base)
      ch : Char;
      property Alpha read ch write ch; (*case 1*)
      property BesaProp; (*case 2*)
    end;

begin
end.

There are two basic causes of this error. The first is the specification of a new property without specifying a type; this usually is not supposed to be a movement to a new visibility level. The second is the specification of a property which should exist in the base class, but is not found by the compiler; the most likely cause for this is a simple typo (as in "BesaProp"). In the second form, the compiler will also output errors that a read or write clause was expected.


program Solve;

  type
    Base = class
    private
      a : Integer;
      property BaseProp : integer read a write a;
    end;

    Derived = class (Base)
      ch : Char;
    public
      property Alpha : Char read ch write ch; (*case 1*)
      property BaseProp; (*case 2*)
    end;

begin
end.

The solution for the first case is to supply the type of the property. The solution for the second case is to check the spelling of the property name.