MATLAB Object-Oriented Programming

(Joyce) #1

Define Custom Event Data


In this section...
“Class Event Data Requirements” on page 11-6
“Define and Trigger Event” on page 11-6
“Define Event Data” on page 11-7
“Create Listener for Overflow Event” on page 11-8

Class Event Data Requirements


Suppose that you want to create a listener callback function that has access to specific
information when the event occurs. This example shows how by creating custom event
data.

Events provide information to listener callback functions by passing an event data
argument to the specified function. By default, MATLAB passes an event.EventData
object to the listener callback. This object has two properties:


  • EventName — Name of the event triggered by this object.

  • Source — Handle of the object triggering the event.


Provide additional information to the listener callback by subclassing the
event.EventData class.


  • Define properties in the subclass to contain the additional data.

  • Define a constructor that accepts the additional data as arguments.

  • Set the ConstructOnLoad class attribute.

  • Use the subclass constructor as an argument to the notify method to trigger the
    event.


Define and Trigger Event


The SimpleEventClass defines a property set method (see “Property Set Methods” on
page 8-56) from which it triggers an event if the property is set to a value exceeding a
certain limit. The property set method performs these operations:

11 Events — Sending and Responding to Messages

Free download pdf