DoStuff works on integers, not on properties.
The concept of the routine is:
<take input>
do some magical stuff that nobody really cares about, like a blackbox.
<return output>
I would be quite happy with this, saves me lots of trouble.
The parameter could be considered a temporarely variable which kind of
breaks the "var" concept.
Properties don't really have memory cells or variables, they can behind the
scenes, but it's not required.
Delphi apperently has this weird syntax which allows:
procedure Test( var I : integer );
begin
@I;
end;
var
a : integer;
Test( A );
@A
Address of I = Address of A.
This would no longer be true with the proposed solution.
Instead
Address of I = address of temporarely variable
Address of A = does not exist.
So what if the routine is fooled... there is no real variable to start with.
The only thing the compiler could do is hint at/warn the programmer that the
routine is taking the address of a compiler generated temporarely variable
which was created to be able to pass the property to the routine/parameter.
So the compiler warns:
The compiler generated a temporarely variable to be able to pass the
property to the var parameter of the routine. Address of parameter is
address of temporarely variable. After routine exists temp variable is
assigned to property and temp variable goes out of scope/is cleaned up.
The compiler could detect this at compile time, or if this is too complex,
use debugging code to detect this, however I think it's probably pretty easy
for the compiler, because it can already detect that the programmer is
trying to pass a property to a var parameter which is currently not allowed.
So if properties are now allowed to be passed, the compiler knows it has to
scan the routine for any "address of" operators.
If the compiler finds any "address of" operators it warns the programmer the
routine is possibly taking the address of the parameter.
Further scanning of the routine and it's code could give certainty.
This feature would save me lots trouble and thus time and the same would
probably apply to many other programmers as well.
And it would create nice and powerfull possibilities.
This is definetly NUMBER ONE feature I would like to see implemented for
next version of Delphi ;)
If it is not implemented I will end up in "update" hell:
For example:
vTemp := Tsomething.SomeWhere.WhoKnows.Property;
SomeRoutine( vTemp );
Tsomething.SomeWhere.WhoKnows.Property := vTemp;
I would rather just write:
SomeRoutine( Tsomething.SomeWhere.WhoKnows.Property );
1. It's shorter, saves many lines.
2. It's easier, the compiler creates the temporarely variables instead of
the programmer.
3. It's safer, no stupid mistakes, like:
3.1 Forgot to read the property into the temp variable.
3.2 Forgot to write the temp variable back to the property.
4. It's easier to write consistent code, instead of which one shall I use
for next line: temp variable or property ?
5. Properties allow the value returned from the routine to be modified
further because the compiler immediatly calls the setter before throwing
away the temp variable.
Performance wise it doesn't matter that much unless the temporarely variable
was re-used for many lines of code by the programmer
this would save some property getters/setters calls.
This is a trade-off which the programmer will have to decide about:
"It's it worth using a explicit temp variable for multiple lines of code to
get a performance improvement ?"
"Or shall I let the compiler take care of it ;) and have the benefits
mentioned above"
My solution now looks like:
Tsomething.SomeWhere.WhoKnows.ReadRealFieldIntoTempField; // procedure
SomeRoutine( Tsomething.SomeWhere.WhoKnows.TempField ); // field
Tsomething.SomeWhere.WhoKnows.WriteTempFieldToRealField; // procedure
This prevents having to use local temp variables on the stack, and instead
temp variables are in the record itself.
But still needs the update hell.
And it's not handy for temp arrays... because that's bad for performance.
So I used index properties to access array elements.
That means I can't pass the array elements to var parameters... because they
are "propertied".
In other words currently properties can be a big drawback while coding.
This feature/solution would erradicate this very nasty drawback.
Bye,
Skybuck.