That works because the compiler creates a reference back to the return of the record.. As I stated before, records are large data types and the compiler creates a reference back to it..
Class pointers are not large data types and it just simply recreates one locally or has a junk pointer if you don't create one locally in the operator function and there for makes it impossible to code out a function not a procedure in your code that can interact with the return object without actually creating one in the function...
C++ does this sort of thing a lot with the & symbol... It tells the compiler to use a pointer that is initialized to the returning object so that one can directly interact on the return object inside the function as if it was already created..
of course you can create a new class inside the function if you wish, it will only be interacting with the returned object which lives outside the function body but you have access to it via the REFERENCE pointer.
So looking at a procedure or Function (Var Name:AClassType), here the NAME is a reference back to the input object but that isn't what I want, I want to code it like a function and this gain access to the returning object's real body not have the function create a new object(Class)…
So using the RETURN.SomeMember := ? will simply directly interact with the object that would normally get overwritten when the function returns..
Why would want to do such things you may ask?
it is to make a choice if you want to reuse an existing object that is already living and simply modify it a little there by making a change to it or totally replace it which then starts a memory operation .
And all of this us being done in a FUNCTION way not a procedure way so it looks natural...
The simple fix for this would be to give a new option when defining a function as I said before...
Function NAme(…..) VAR ReturnType;
^^^
that would force the compiler to call it the same way as it would if it were dealing with a Large Data type, a record for example.
Also, there should be some restrictions on its use, with the {$E+} on, the compiler should not allow these types of functions to be used as procedures.