Callbacks and event.EventData (specifically timer)

3 ビュー (過去 30 日間)
Daniel Shub
Daniel Shub 2011 年 4 月 13 日
回答済み: Taylor 2025 年 7 月 17 日
From my understanding when writing callback functions, the function needs a signature like: callbackfcn(src, evt), where src is the handle to the object that initiated the callback and evt is the associated "event data".
When a uicontrol initiates my callback function, evt is of the class event.EventData, but when a timer initiates my callback function, evt is of the class struct. Although the fields of the struct are such that it makes the two cases similar, I was surprised by the difference.
Can someone help me understand why sometimes the event data is a struct and other times event.EventData.

回答 (1 件)

Taylor
Taylor 2025 年 7 月 17 日
When UI controls were incorporated into the modern event system, they adopted the event.EventData class-based model. Timers, implemented before this, retained a simpler struct-based approach.
event.EventData allows subclassing, so for advanced or custom behavior (as with custom UI components), you can pass more detailed information by creating subclasses.
Both systems provide comparable information, but object-oriented event data is more robust and extensible for complex GUI interactions. Timer event data as a struct is sufficient for timer-related callbacks but less flexible for extension or integration with the rest of MATLAB's event model

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by