Get UI object name

7 次查看(过去 30 天)
Matt C
Matt C 2024-3-20
评论: Matt C 2024-3-20
I am saving an app state so it can be loaded later. I add tags to the numeric edit fields that need to be saved. I pull all the object handles, find those that are tagged, and save whatever properties I need to restore in text/.mat. The issue is I am trying to make it open-ended such that adding a non-specific tag is all that I have to do to get a field to save. I want to store the name of the object with the saved properties so that I can match up when loading. I get that I can give them a unique ID, but they already have names in my app. The name doesn’t appear to be a property in the uinumericeditfield object. Is there another way to query the name of the object in the app once I have its handle?

回答(1 个)

Walter Roberson
Walter Roberson 2024-3-20
No. You are working with handles, and there are multiple names for the same handle. You can chase the Parent property to get the shortest path to the root, but that doesn't tell you the "name" of anything.
  1 个评论
Matt C
Matt C 2024-3-20
I was afraid of that. I figured a workaround for it, but I am still hoping there is a better way that I am missing...see code below that pulls the name of the object and the value for all objects with 'S' tag...
s=properties(app);
c=0;
for i=1:length(s)
if strcmp(app.(s{i}).Tag,'S')
c=c+1;
app.D(c).objname=s{i};
app.D(c).val=app.(s{i}).Value;
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by