On Tue, 15 Feb 2022, Ryan Joseph via fpc-pascal wrote:
This has been a constant problem for me with FPC and wanted to make a formal post with code examples since I've only mentioned it in passing before. How can it be achieved to have a caller agnostic procedure variables? I've tried making some big crazy dispatch record that uses generics but because generics don't support variable templates (like some languages have TClass<T...>) it was limited and clunky to use. The problem is that from the perspective of the receiver it shouldn't really care what the caller has provided except for that there is a procedure that needs to be called. For example if there is a "sort" function that takes a procedure variable it shouldn't care if the procedure is a global function, a method or a nested function (and eventually a closure). It feels like the compiler needs a new type which encapsulates these different types but I'm not sure how this all works internally. Any thoughts on this?
I've answered this question before: The "Reference to procedure" that will be part of anonymous functionswill do this for you. Michael. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal