<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Di., 15. Feb. 2022, 13:14:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Feb 15, 2022, at 5:15 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> It contains a capture object that backs the method. <br>
> If nothing is captured and the right hand side is a direct function or method pointer then the compiler could in principle create something that is essentially static to avoid allocations, but that would be a future optimization. <br>
> <br>
<br>
So if we do this there is nothing being captured right? In that case we get an interface which can call a function pointer? Does the interface then know about "of object" and "is nested" types at all or does it use a totally different mechanism to call those?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">A function reference is simply an interface of which the Invoke method can be called on the instance instead of manually doing "Foo.Invoke".</div><div dir="auto"><br></div><div dir="auto">The real "magic" is when the compiler generates the *implementation* of said interface. So in the end what can be assigned to a function reference depends on the compiler being able to generate suitable implementations. </div><div dir="auto"><br></div><div dir="auto">Anonymous functions are a given. Global functions and methods are required to work as well. Nested functions can be made to use as well. Function and method variables can be supported relatively easily as well. Only nested function variables are hard to support. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div></div>