MATLAB Object-Oriented Programming

(Joyce) #1

  • Event data — a event.PropertyEvent object containing information about the
    event


You can pass additional arguments if necessary. It is often simple to define this method as
Static because these two arguments contain most necessary information in their
properties.


For example, suppose the handlePropEvents function is a static method of the class
creating listeners for two properties of an object of another class:


methods (Static)
function handlePropEvents(src,evnt)
switch src.Name
case 'PropOne'
% PropOne has triggered an event
...
case 'PropTwo'
% PropTwo has triggered an event
...
end
end
end


Another possibility is to use the event.PropertyEvent object's EventName property in
the switch statement to key off the event name (PreSet or PostSet in this case).


“Class Metadata” on page 16-2 provides more information about the meta.property
class.


Add Listener to Property


The handle.addlistenerhandle class method enables you to attach a listener to a
property without storing the listener object as a persistent variable. For a property event,
use the four-argument version of addlistener.


Here is a call to addlistener:


addlistener(EventObject,'PropOne','PostSet',@ClassName.handlePropertyEvents);


The arguments are:



  • EventObject — handle of the object generating the event

  • PropOne — name of the property to which you want to listen

  • PostSet — name of the event for which you want to listen

  • @ClassName.handlePropertyEvents — function handle referencing a static
    method, which requires the use of the class name


Listen for Changes to Property Values................. 11-

Free download pdf