Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Callback and Thisback Function call parameters
Callback and Thisback Function call parameters [message #43429] Tue, 29 July 2014 11:50 Go to next message
NilaT is currently offline  NilaT
Messages: 70
Registered: November 2011
Location: Austria
Member
Hi everybody, I've got a new question for you, which is driving me nuts.
Callbacks and Thisbacks are quite difficult for beginners, but I think I got them... almost Wink

One thing is still unclear to me.
How can I add Parameters to a Function which is called, when a callback occurs?

For example:
Somewhere I got this:
Callback2<Point, Point>	 WhenProductChanging;


and then I got this, somewhere
...
WhenProductChanging(p1, p2);
...


And somewhere else I got this:
xxx.WhenProductChanging = THISBACK(OnProductChanging);


And finally, I got the function itself:
void yyy::OnProductChanging(Point firstP, Point secondP)
{ /* do something */
}


Now, what I want is to add another parameter to my "OnProductChanging" Method, like for example:
void yyy::OnProductChanging(Point firstP, Point secondP, int newParameter)
{ /* do something */
}


So I thought I have to change the THISBACK to THISBACK1 and pass the parameter after the Methodname, like this:
xxx.WhenProductChanging = THISBACK1(OnProductChanging, 1);


But this doesn't work, because it seems that all necessary parameters come from the callback. How can I pass another parameter, which is defined somewhere else and not known in the "callback-calling" function?

Thanks in advance!

[Updated on: Tue, 29 July 2014 11:51]

Report message to a moderator

Re: Callback and Thisback Function call parameters [message #43430 is a reply to message #43429] Tue, 29 July 2014 12:53 Go to previous messageGo to next message
ManfredHerr is currently offline  ManfredHerr
Messages: 67
Registered: February 2013
Location: Germany
Member
To have three parameters in your callback you have to use Callback3 template class,
i.e. Callback3<Point, Point, int> WhenProductChanging;
in your case. See Cbgen.h for definition.

[Updated on: Tue, 29 July 2014 12:55]

Report message to a moderator

Re: Callback and Thisback Function call parameters [message #43431 is a reply to message #43429] Tue, 29 July 2014 13:04 Go to previous messageGo to next message
NilaT is currently offline  NilaT
Messages: 70
Registered: November 2011
Location: Austria
Member
The problem is, at the Callback definition, I only have 2 Parameters.
The third is used at another place and is not known at the point of definition. (int was just an example, in real it's a pointer to an own class)
So, I have to add the third parameter afterwards...
Is there a way to change a Callback2 to a Callback3 during runtime?


//edit: After reviewing our class hierarchy I discovered, that the needed class is there and I can use it, so I changed Callback2 to Callback3 and it works fine.
Nevertheless, is it possible to add parameters to the called function beside those that come from the Callback itself, like shown above?
Just in case the parameter is an object from a class thats not known in the Callback calling function...

[Updated on: Tue, 29 July 2014 13:46]

Report message to a moderator

Re: Callback and Thisback Function call parameters [message #43432 is a reply to message #43431] Tue, 29 July 2014 15:44 Go to previous messageGo to next message
ManfredHerr is currently offline  ManfredHerr
Messages: 67
Registered: February 2013
Location: Germany
Member
I recommend to read the help in theide regarding callbacks. Cross read the text with the C++ code in Cbgen.h and you will know what is possible. Adding parameters to a function interface depending on the call isn't possible in neither function/method. The only possibility I know is to use a C-function with varargs. But I doubt that this is what you intend.
Re: Callback and Thisback Function call parameters [message #43434 is a reply to message #43429] Tue, 29 July 2014 16:57 Go to previous message
NilaT is currently offline  NilaT
Messages: 70
Registered: November 2011
Location: Austria
Member
Okay, thanks.
I'm happy as long as it works now Wink

Would be a great feature though...
Well, thanks anyway.

Greets
Previous Topic: Display of long text
Next Topic: Adding a do not compile flag to a project?
Goto Forum:
  


Current Time: Thu Mar 28 17:50:11 CET 2024

Total time taken to generate the page: 0.01174 seconds