Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.
Los eventos son emisiones de avisos que se transmiten cuando se produce algún cambio o acción que involucra a un objeto. Los elementos de escucha definen funciones que se ejecutan cuando se producen eventos específicos. Las clases pueden definir y activar eventos. MATLAB® puede activar eventos predefinidos cuando el código accede a las propiedades de los objetos.
events | Event names |
handle.notify | Notify listeners that event is occurring |
handle.addlistener | Create event listener bound to event source |
handle.listener | Create event listener without binding to event source |
event.hasListener | Determine if listeners exist for event |
event.EventData | Base class for event data |
event.listener | Class defining listener objects |
event.PropertyEvent | Data for property events |
event.proplistener | Define listener object for property events |
Use events and listeners to send and respond to messages.
Events broadcast notifications to all registered listener and pass event-specific data to listener callback functions.
These code examples show how to define events and listeners
Specify a list of classes that can be notified of a specific event.
Control access to events by setting event attributes.
Specify listener callbacks using function handles.
Errors in listener callbacks do not prevent execution of other listeners. However, the order of listener execution is not defined.
MATLAB manages the lifecycle of listeners. For greater control of listener lifecycle, constructor listener objects using the handle.listener
method instead of handle.addlistener
.
Determine If Event Has Listeners
You can determine if there are listeners defined for a specific event and event source.
Listen for Changes to Property Values
MATLAB defines pre and post set and get events for all properties.
Assignment When Property Value Is Unchanged
Prevent the triggering of property events when values do not change using the property AbortSet
attribute.
Redefine the event data that MATLAB passes to listeners when an event is triggered.
Observe Changes to Property Values
Listeners can respond to changes in the value of properties using predefined property events.
Implement Property Set Listener
Listeners can respond to changes in property values before or after MATLAB assigns the value.
Techniques for Using Events and Listeners
This example shows how to enable and disable listener execution using context menus.
You can restore property listeners from the loadobj
method.