[Lazarus] Passing properties as var paramatars (was: Delphi editor clone)

Michael Van Canneyt michael at freepascal.org
Sat Nov 7 18:07:00 CET 2009



On Sat, 7 Nov 2009, Marco van de Voort wrote:

> On Sat, Nov 07, 2009 at 01:44:39PM +1000, Alexander Klenin wrote:
>> 1) The change was correct in the sense that all properies should be treated
>> begin
>>   temp := MyObj.MyIntProperty;
>>   Inc(temp);
>>   MyObj.MyIntProperty := temp;
>> end;
>>
>> Of course, if the compiler determines that the property is an alias for a field,
>> it is free to pass the field directly -- but this is only an optimization.
>
> This is not orthogonal. VAR parameters are generally updated
> instantaniously. By delaying the update over a temp variable you break
> another aspect of the VAR parameter.

Not to mention the various reference counted objects: strings, interfaces, 
open arrays. Unexpected results abound...

Maybe we should put this question in the FAQ.

Michael.




More information about the Lazarus mailing list