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 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