Home » Community » Newbie corner » Basic question regarding callbacks
Basic question regarding callbacks [message #27015] |
Mon, 21 June 2010 13:47 |
281264
Messages: 270 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
I am completely new in Ultimate++, so one thousand apologizes if I ask very basic questions.
My question is regarding functioning of callbacks. As reference let’s take the example 7 Menu contained in the GUI Tutorial, which I am copying here for convenience:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyAppWindow : TopWindow {
MenuBar menu;
void Exit() {
if(PromptOKCancel("Exit MyApp?"))
Break();
}
void SubMenu(Bar& bar) {
bar.Add("Exit", THISBACK(Exit));
}
void MainMenu(Bar& bar) {
bar.Add("Menu", THISBACK(SubMenu));
}
typedef MyAppWindow CLASSNAME;
MyAppWindow() {
Title("My application with menu").Sizeable();
AddFrame(menu);
menu.Set(THISBACK(MainMenu));
}
};
GUI_APP_MAIN
{
MyAppWindow app;
app.Run();
}
Question 1: What is really happening when menu.Set(THISBACK(MainMenu)); is executed?.
Question 2: I guess that menu.Set is the method void Set(Callback1<Bar&> menu) described in the Menu Class help; if that is ok, the expected argument is a Callback1, which subsequently ask for TWO arguments [as indicated in template <class Object, class M, class P, class T> Callback callback1(Object *object, void (M::*method)(P), T arg)]. Why are we passing only the methid MainMenu and not both the ManiMenua and the expected argument menu?.
Question 3: How is MainMenu executed from menu.Set(THISBACK(MainMenu)) if we do not pass the argument bar?.
Question 4: I tried to debug the code and added some breakpoints (for example in manu.Set(..). But the debugger do not work and enters in an infinite loop; what is happening?
Sorry again for my clumsiness and my lack of knowledge of C++.
Best wishes and many thanks.
|
|
|
Goto Forum:
Current Time: Mon Apr 29 05:48:39 CEST 2024
Total time taken to generate the page: 0.03667 seconds
|