3 ms·
This is literally how Delphi implements closures/anonymous methods. The compiler will generate a class with fields for whatever variables are captured, and the
by magicalhippo 6y ago
This is literally how Delphi implements closures/anonymous methods.
The compiler will generate a class with fields for whatever variables are captured, and then instantiate it for you, assign the fields etc.
If you define your function reference as a type (as it's called), you can even inherit[1] from it and add additional overloads to the inherited class, to make it do multiple things.
[1]: https://delphisorcery.blogspot.com/2015/06/anonymous-method-overloading.html https://delphisorcery.blogspot.com/2015/06/anonymous-method-...