Hi all,
you guys helped me out before, I hope you can with this thing I'm trying, actually it is working but I would like to do it in another cleaner/better way for learning purposes. I work within the limitations of a framework which is written by other people and for several reasons I did some 'hacking' to achieve better results.
I have a window class (a bit like a form) in which I have several buttons classes of my own. The reason for not using the framework buttons is that their navigation order (comparable to tab order in windows navigation) behaves like an invention of the devil himself. The consequence is that I have to do the navigation myself. So I know when a button will be pushed because my code "pushes" it.
To do all this I made several inherited button classes each having it's own OnDown function in which a function of the only instance of the window class is called.
So there are several things I do not like:
- if I were to create several instances of the window this would mean I have to double the number of inherited button classes
- why do I need to inherit the button classes if the only thing that differs is the OnDown function
I am trying to solve this by first passing a pointer to the function that needs to be executed in the window class to the button class. And I'm trying to do this IN the window class. That way I can change what the button needs to execute before my code "pushes" it.
If I would succeed in this I think I overcome both my problems. Of course, as you can guess, I do not succeed because I do not fully master the concept nor the syntax. I have tried all combinations I can think of and always the compiler was complaining.
Help is appreciated!
Here is my idea in codeform:
CButton::CButton(...) : CButtonParent(...)
{
...
functionPointer
...
}
CButton::SetOnDownFunction(pointer)
{
this->functionPointer = pointer
}
CButton::Push()
{
...
executer fuction from functionPointer
...
}
CWindow::CWindow(...) : CParentWindow(...)
{
firstButton = new CButton();
firstButton->SetOnDownFunction(pointer to OnFirstButtonDown);
secondButton = new CButton();
secondButton ->SetOnDownFunction(pointer to OnSecondButtonDown);
thirdButton = new CButton();
thirdButton->SetOnDownFunction(pointer to OnThirdButtonDown);
}
CWindow::OnFirstButtonDown(){...}
CWindow::OnSecondButtonDown(){...}
CWindow::OnThirdButtonDown(){...}
CWindow::OnNavigate()
{
...
firstButton->Push();
...
secondButton->Push();
...
thirdButton->Push();
...
}