How do I limit the scope of a listener created by using ADDLISTENER in MATLAB 8.0(R2012b)?
1 view (last 30 days)
Show older comments
I need to create a listener handle whose lifecycle is not tied to the source of the event. ADDLISTENER does not create this type of a listener handle. I need to define a handle whose scope I can control. How do I do this?
Accepted Answer
MathWorks Support Team
on 29 Mar 2013
A listener handle created using addlistener is tied to the object that is the source of the event. For eg.,
lh = addlistener(Hsource,'EventName',callback)
Here, the lifecycle of lh is same as the lifecycle of Hsource.
You can still control its scope by using the DELETE command as follows:
delete(lh)
Alternatively you can use event.listener, in this case the listener handle is not tied to the source of the event. Therefore, it does not exist outside the scope of its definition. Thus, no events outside the function will trigger this listener.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!