Callbacks and event.EventData (specifically timer)

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by