[Lazarus] Passing properties as var paramatars (was: Delphi editor clone)
Mattias Gaertner
nc-gaertnma at netcologne.de
Sat Nov 7 11:19:56 CET 2009
On Sat, 7 Nov 2009 13:44:39 +1000
Alexander Klenin <klenin at gmail.com> wrote:
>[...]
> 2) However, there is an obvious room for improvement here:
> not only Inc/Dec, but any procedure accepting var parameter
> should be able to accept writeable property of the same type.
Var parameters must fit exactly for typecasts and pointers.
procedure DoIt(var i: integer);
begin
DoSome(@i);
end;
This is not possible with a Setter function.
> (especially common example is Include/Exclude for set properties)
>
> For each property argument, the compiler should create temporary
> variable, set it by reading the property before the function call,
> and set property to the new value
> after the call.
>
> Inc(MyObj.MyIntProperty);
> =>
> var
> temp: Integer;
> 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.
I guess this would be possible for compiler functions like inc.
Mattias
More information about the Lazarus
mailing list