Bind delegate with one parameter
I am trying to bind a delegate with a predefined parameter (payload). I am having a hard time with the syntax, so I'd appreciate some help as I have tried to look up a lot of examples but to no avail. Something along the lines of:
I have tried it with binduobject and others(create*) with no avail. It spits out various errors the different ways I write it. Some help with binding this delegate with a payload so I can use it later (in a timer for example) would be much appreciated.
asked Oct 07 '14 at 03:32 PM in C++ Programming
A few problems here. First of all, a delegate definition describes how you want to call the delegate, not the signature of the functions it's bound to. If you want to bind 1 to a function 'void MyFunction(uint8)' (I'm guessing - you didn't specify the definition of your function), it means you want the delegate to always pass 1 as that argument, which means that you pass zero arguments to the call.
Second, the bound variables needs to match the types of the delegate parameters precisely. So even though 1 is convertible to uint8, you need to cast it instead, like (uint8)1, which forces the type to be uint8 and the binding to be recognised.
So, I'm thinking your class wants to look something like this:
This is a simple example.
More generally, bound variables are applied to the end of delegated calls, so a more complex example might look something like this:
Hope this helps.
answered Oct 15 '14 at 12:07 PM
Steve Robb STAFF
It should be like this, DECLARE_DELEGATE will generate RefreshOne variable for you, thats what this macro is for:
Now you bind it by doing this:
And you trigger the event using
The delegate you using is monocast delegate, you can set only bind one function, when you bind again it will be replaced, you can declere multicast delegate where you can bind multiple functions using this
and then you bind functions using
Follow this question
Once you sign in you will be able to subscribe for any updates here