Martin schrieb:

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 had the same ideas once too.

The answer was that properties are meant to change the value on the object immediately. Also a property setter can raise an exception, or additional actions can take place or the value can be substituted....
All this wouldn't happen with a temp variable (or at best deferred).

This *also* will happen in the above code, when the temporary variable is loaded or stored.

When the compiler erroneously bypassed getters and setters in the past, this error could have been fixed in that place, without any further impact on existing (compiler and application) code.

DoDi


--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to