[fpc-pascal] Class helpers and properties

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Fri Jan 27 23:51:12 CET 2012


Sven Barth wrote:
> 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;
>> ...

Note that below is in a different unit.

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

That didn't work since once we're in the helper it can't see fValue 
since it's only visible in the original unit.

Obviously code in the helper can simply call SetValue(), but I thought 
it worth raising in case I was missing something obvious.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list