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 » Focus problem
Re: Focus problem [message #57816 is a reply to message #57812] Sun, 19 December 2021 14:22 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
Hi Silvan:

The way I define WhenSuspiciousKey is a typical way to define an Event. First, the Ctrl or its direvative need to provide a chance for the event in a (relevant) overrided virtual function. In my case, I overrided
bool Key(...)

In my MainWindow::Key(...)
I allowed WhenSuspiciousKey be called at certain time. What is WhenSuspiciousKey? I define it as a member variable of MainWindow of type Event<>

By add this member variable to MainWindow, the user of MainWindow can assign a callback to an instance(object) of this type by
MainWindow m;
m<<[]{...};


There is no magic here. C have simlar (but much limited ) mechanism. WhenSuspiciousKey is like a function pointer to which you can assign a callback. In order for this callback to actually be called, some where, you need to check and call it(in our case, it's in the MainWindow::Key(...) virtual function).

Now, Key is a virtual function, you cannot assign a callback to it. On the other hand, an object of MainWindow, m, has a public member variable name WhenSuspciciousKey, which is of type Event<>. You can access this member variable. One way is by something like
m.WhenSuspiciousKey<<[]{};


-----
PS: On a second thought, use C function pointer as example:
void (*WhenWhat)(int);

void func1(int p)
{
   if(WhenWhat)
      WhenWhat(p);
}

void callback(int p)
{
}

WhenWhat=callback; // this is good
// just like
// WhenSuspiciousKey<<[]{};
// is fine
func1=callback; // this won't compile
// just like
// Key<<[]{};
// won't compile.

[Updated on: Sun, 19 December 2021 15:02]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to output variable values with time stamp in windows application
Next Topic: Clang linker error: no such file or directory
Goto Forum:
  


Current Time: Sun Aug 24 14:18:54 CEST 2025

Total time taken to generate the page: 0.00434 seconds