Forwarded from marcov@stack.nl (Marco van de Voort):
In gmane.comp.compilers.gpc, you wrote:
It works though with uninitialised objects too as long as you don't actually "use" (dereference) self:
I see. But I suppose Markus also wants to call the method via the procedural variable later and apply it to a certain object instance (selected at call time), something like (depending on the syntax chosen):
Not possible directly, however messing with the internals (via the tmethod record typecast) is "supported". IOW, people expect it to work on Delphi.
procedure test;
var localx : somemethodvar;
begin localx:=globalmethodvarref; // local copy, avoid global mod of complex constant. tmethod(localx).data:=otherinstance; // maybe typecast to pointer end;
the problem is of course that the assignment is not safe. However usually code that messes with instances of procvars is typically framework internal, and not in normal user code, so I don't have a particular problem with it. (at least not enough to invent new syntax)
A slight advantage of the delphi method is that it requires dirty syntax to do dirty things. That could be seen as a deterrent.
Of course, that can be a problem -- as always if not carefully used. BTW, do you warn if taking the address (@) of a normal (non-object) variable on the stack?
Not this moment. But IMHO it should, though we would probably call it a "hint" (something that is not _always_ wrong).