This error message will be issued in several different situations:
program Produce; type TMyBase = class Field: Integer; end; TMyDerived = class (TMyBase) Field: Integer; function Get: Integer; Automated property Prop: Integer read Field; (*<-- Error message here*) end; function TMyDerived.Get: Integer; begin Result := TMyBase.Field; (*<-- Error message here*) end; begin end.
The example tried to declare an automated property that accesses a field directly. The second error was caused by trying to get at a field of the base class - this is also not legal.
program Solve; type TMyBase = class Field: Integer; end; TMyDerived = class (TMyBase) Field: Integer; function Get: Integer; Automated property Prop: Integer read Get; end; function TMyDerived.Get: Integer; begin Result := TMyBase(Self).Field; end; begin Writeln( TMyDerived.Create.Prop ); end.
The first problem is fixed by accessing the field via a method. The second problem can be fixed by casting the Self pointer to the base class type, and accessing the field off of that.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|