blitzkriegten wrote:Hi All,
I am wondering about he advantage of using Connect() method ? If anyone having any idea, please let me know.
I know of three advantages:
- As mentioned above, Connect() lets you handle events outside the originating class hierarchy.
It's dynamic, so it's useful when you want to deal with a variable number of controls e.g. the user adding buttons to a toolbar. There are ways of doing this with event tables (EVT_MENU_RANGE, or wxID_ANY) but Connect() is a more elegant solution.
You can Disconnect() when you don't want to receive more events. I use this when I only want to do something once, e.g. when a newly-created control has achieved its proper size: Connect() idle events on creation, check with GetSize() in the handler, do what's needed if the size is genuine, then Disconnect().
The main drawback is that it's so much easier to get Connect() wrong, usually because of an incorrect eventSink parameter. Search this forum, and you'll see lots of pleas for help with Connect(), but far fewer for event tables.
wendahan: PushEventHandler should work too. I've not used it in this way. but iiuc that means that
all MyClass events, of all types, will go first to 'parent'. This will usually not be what is wanted, and there is obvious scope for error and confusion.
Regards,
David