Class: handle
Create event listener without binding to event source
eL = listener(hSource,EventName,callback)
eL = listener(hSource,PropertyName,EventName,callback)
creates a listener for the event named eL
= listener(hSource
,EventName
,callback
)EventName
. hSource
is a handle object that is the source of the event. callback
is a function handle that MATLAB® invokes when the event is triggered.
If hSource
is an array of event source objects, the listener responds to the named event on any object in the array that is not in a deleted state.
creates a listener for one of the predefined property events. There are four predefined property events:eL
= listener(hSource
,PropertyName
,EventName
,callback
)
Event Name | Event Occurs |
---|---|
PreSet | Immediately before the property value is set, before calling its set access method |
PostSet | Immediately after the property value is set |
PreGet | Immediately before a property value query is serviced, before calling its get access method |
PostGet | Immediately after returning the property value to the query |
To remove a listener, delete the listener object returned by listener
. For example, this statement calls the handle class delete
method to remove the listener.
delete(el)
Calling delete on the listener object destroys the listener and, therefore, the event no longer causes the callback function to execute.
The listener
method does not bind the listener's lifecycle to the object that is the source of the event. Destroying the event source object does not affect the lifecycle of the listener object.
You must explicitly destroy listeners created with the listener
method independently of the source object. Calling the handle delete method on the listener variable (for example, delete(el)
) explicitly destroys the listener. Redefining or clearing the variable containing the listener can delete the listener if there are no other references to it. To bind the lifecycle of the listener to the lifecycle of the event source object, use addlistener
.
Use addlistener
when you want MATLABto manage the listener lifecycle.