event.hasListener
Tests whether an event of an object has listeners.
Category: Programming > Classes
Syntax
tf = event.hasListener(obj, 'EventName')
Returns true if at least one listener is attached to the event of obj.
Description
A class that triggers events can use this test to skip building expensive event data when nobody is listening. Listeners created with addlistener or listener count as long as they exist and are enabled, and deleting them makes the answer false again.
Input arguments
obj- A handle object.
'EventName'- Name of an event of the object's class.
Output arguments
tf- Logical scalar.
Example
Before and after adding a listener
m = containers.Map();
event.hasListener(m, 'ObjectBeingDestroyed')
lh = addlistener(m, 'ObjectBeingDestroyed', @(s, e) disp('gone'));
event.hasListener(m, 'ObjectBeingDestroyed')
delete(lh)
event.hasListener(m, 'ObjectBeingDestroyed')
Output
ans = logical
0
ans = logical
1
ans = logical
0