Matlab - app designer - component name and callback

Hi,
In App Designer
How can we know the name of a modified component when his callback is also connected to other component ?
Thks

댓글 수: 2

Are you asking how to idenitify which component invoked a callback function in the case where multiple components are assigned the same callback function?
Yes!

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2019년 8월 21일
편집: Adam Danz 2019년 8월 22일

2 개 추천

The 2nd input to a callback function in App Designer is "event'. event.Source is the handle to the object that invoked the callback function. event.EventName is the name of the event (a string).
objHandle = event.Source;
objName = event.EventName;

댓글 수: 4

I am sorry but it doesn't work
event.EventName give 'ValueChanged'
Yes, EventName is the name of the event, and it's useful if the same callback is used to catch different types of events. It has nothing to do with what object triggered the callback,
However, as Adam said, the Source property is the handle to the object that triggered the callback so that's what you should use.
Objects don't really have names. However, you can assign most (all?) objects a name by assigning a string to their Tag property. Then you can identify the object by its tag like this
objHandle = event.Source;
objHandle.Tag
If you haven't assigned a Tag, the tag property will be empty.
Hy Guillaume,
could you please explain in detail what you mean with " it's useful if the same callback is used to catch different types of events. " I dont get the point out of this phrase. Do you have a minimal example fot this?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기

질문:

2019년 8월 21일

댓글:

2022년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by