Listener callback casts custom event data back to event.eventData?

18 ビュー (過去 30 日間)
Simon Ahrens
Simon Ahrens 2018 年 10 月 9 日
回答済み: Taylan Kanber 2022 年 1 月 10 日
I have a simple subclass of event.EventData to pass data to listeners:
classdef (ConstructOnLoad) tuningEventData < event.EventData
properties
path
value
end
methods
function obj = tuningEventData(path, value)
obj.path = path;
obj.value = value;
end
end
end
I trigger an event, passing a tuningEventData object:
notify(obj, 'tuningChange', tuningEventData(path, val));
Now I have one listener receiving this and triggering yet another event in its callback method, which I'd like to pass on the same tuningEventData object:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', data);
end
But listeners to this new event do not receive the tuningEventData object. They receive an EventData object instead which obviously doesn't have the path and value properties.
The only way to pass on a tuningEventData object seems to be creating a new object in the first listener's callback:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', tuningEventData(data.path, data.value));
end
Why can't I just send the data object straight on? Is my tuningEventData class missing something?

回答 (1 件)

Taylan Kanber
Taylan Kanber 2022 年 1 月 10 日
Change obj.path and obj.value to data.path and data.value

カテゴリ

Help Center および File ExchangeEvents についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by