[fpc-pascal] Class helpers and properties

Sven Barth pascaldragon at googlemail.com
Fri Jan 27 23:03:15 CET 2012


On 27.01.2012 22:46, Mark Morgan Lloyd wrote:
> If a class has a public reader property like this:
>
> TLexemeList= class(TObject)
> protected
> fValue: TPrimaevalValue;
> public
> property Value: TPrimaevalValue read fValue;
> ...
>
> is there a way of allowing a class helper to augment this with a
> protected writer property? My attempt as below messed up the reader:
>
> TLLEvaluator = class helper for TLexemeList
> private
> procedure SetValue(v: TPrimaevalValue);
> protected
> property Value: TPrimaevalValue write SetValue;
> ...
>

In your exact example fValue is protected so the following should work:

property Value: TPrimaevalValue read fValue write SetValue;

Another possibility (for non protected properties):

property Value: TPrimaevalValue read GetValue write SetValue;

...

function TLLEvaluator.GetValue: TPrimaevalValue;
begin
   Result := inherited Value;
end;

Other possibilities don't exist, as a helper's declaration will hide the 
declaration of the extended class (exceptions are methods with 
"overload" defined).

Regards,
Sven



More information about the fpc-pascal mailing list