App Designer: Using app.Component.Value vs. event.Value in callback function

9 views (last 30 days)
I am writing a callback function in App Designer where the user has selected an option from a drop-down menu. It seems to me that there are two ways to obtain the value that the user has selected.
Let us say that I have a callback function
function DropDownValueChanged(app, event)
that refers to my UI component DropDown. It seems to me that there are two ways to get the value that was selected from the drop-down menu. According to the section "Callback Input Argments" of this help page, the options are:
value = event.Value;
or
value = app.DropDown.Value;
Is there any tradeoff between using these two approaches? Why even pass event as an argument to the callback function if the same data is stored in app.Component?

Accepted Answer

Walter Roberson
Walter Roberson on 9 Sep 2022
You can code the exact same callback for multiple components. You would not know immediately which component the event was for. It might not even have a particular name: it might be part of an array of objects. Using the event information gets you what you need immediately.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!