MATLAB Object-Oriented Programming

(Joyce) #1
These events have public listen access (ListenAccess attribute) and private notify
access (NotifyAccess attribute).

The PropertyAdded and PropertyRemoved events pass an
event.DynamicPropertyEvent object to listener callbacks. The event data object has
three properties:


  • PropertyName — Name of the dynamic property that is added or removed

  • Source — Handle to the object that is the source of the event

  • EventName — Name of the event (PropertyAdded, PropertyRemoved, or
    ObjectBeingDestroyed)


Listen for a Specific Property Name


Suppose that you have an application that creates a dynamic property under certain
conditions. You want to:


  • Set the value of a hidden property to true when a property named SpecialProp is
    added.

  • Set the value of the hidden property to false when SpecialProp is removed.


Use the event.DynamicPropertyEvent event data to determine the name of the
property and whether it is added or deleted.

The DynamTest class derives from dynamicprops. It defines a hidden property,
HiddenProp.

classdef DynamTest < dynamicprops
properties (Hidden)
HiddenProp
end
end

Define a callback function that uses the EventName property of the event data to
determine if a property is added or removed. Obtain the name of the property from the
PropertyName property of the event data. If a dynamic property is named
SpecialProp, change the value of the hidden property.

function DyPropEvtCb(src,evt)
switch evt.EventName
case 'PropertyAdded'

8 Properties — Storing Class Data

Free download pdf