Page 1 of 1

Is UnBind() method safe?

Posted: Wed Aug 08, 2018 2:33 pm
by ONEEYEMAN
Hi,
What I am trying to do is the following:

1. On some condition in the program I'm doing Bind(). If condition is false Bind() is not executed. The event I'm binding is wxFileSystemWatcher one.
2. Inside some other event handler I want to execute UnBind() method.

2 questions:
1. If the Bind() was not executed, is it safe to un-bind the event?
2. If the answer to 1 is no - what is the best way to achieve it? I don't think there is an IsEventBound() method...

Thank you.

Re: Is UnBind() method safe?

Posted: Wed Aug 08, 2018 4:32 pm
by Manolo
The docs for bool wxEvtHandler::Unbind say:
Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
The code at common/event.cpp for bool wxEvtHandler::DoUnbind shows that in any other case different from the above the function returns false. IOW, no functor/handler in the dynamic table, then return false.

A good advise is found at http://docs.wxwidgets.org/trunk/overvie ... abled.html:
...if you only bind and unbind same event handler inside same binary, you should be fine
Summary: Is ir safe?, I'd say "yes".