How can I convert a Delegate to TFunction?

You can use a lambda


TFunction<void(int)> fp = [Delegate](int val) { Delegate.ExecuteIfBound(val); };

That will be a bit less efficient, but it’s probably the best you can manage if you want to do this will an arbitrary delegate.

If you don’t need the delegate and just want to bind a member function to a TFunction, you can do


TFunction<void(int)> fp = [this](int val) { Func(val); };

There’s probably a syntax for binding directly to a member function without the lambda, but I don’t know it.

1 Like