Handle type object containing itself
古いコメントを表示
Hello,
I am currently working on a class which should shorten development time for GUIDE application, hopefully I will be able to upload it later for everyone to use - for some reasons I can't share the code now.
The class automatically generates a figure with ui objects according to a template and then starts assigning the ui objects callbacks.
Later on a data source is assigned and loaded to the class.
The hard part is that I don't have the GUIDE handles structure and when I enter a callback I only have hObject and eventdata.
I want to also have access to my class instance. I don't want to use global variables or save/read .mat files so I thought maybe save it in the figure UserData and read it via hObject.Parent.UserData.
As I assigned it I saw a possible problem : The figure is one of the class properties so the class contains the figure and the figure contains the class in UserData, therefore - the class contains itself.
The class inherits for the handle superclass so...Maybe this is ok? Does a handle class behaves like pointers in C so all it does is storing addresses?
Thanks!
4 件のコメント
Rik
2019 年 7 月 28 日
I hardly ever work with classes, so I can't answer your question, but I do have two questions of my own.
There isn't really something GUIDE specific about guidata. It just stores a variable with a figure. So what is your issue with the callback functions? Why are you able to get eventdata at runtime, but not the guidata?
And my second question: why stick to GUIDE in the first place? Its only advantage is the rapid prototyping. Why spend your time making it faster, instead of fundamentally improving it?
Also, AppDesigner is class based as well. What would be the main advantage of your hard work over AppDesigner? This sounds like a massive project, but I don't see how it is better than using pure Matlab or AppDesigner, can you expand on that point a bit?
Dvir Haberman
2019 年 7 月 29 日
Adam
2019 年 7 月 29 日
Since you are using classes anyway wouldn't it make sense to have a class representing the whole UI and the callbacks attached to this class? This is what I have always done (and also what App Designer does). Then you have access to everything you want simply through the class itself.
Rik
2019 年 7 月 29 日
Also, you can simply retrieve the handles struct with the line of code below. That is exactly what GUIDE does as well. (and callbacks don't have/need an output)
handles=guidata(hObject);
As per the documentation of guidata, it will look up the parent figure if you enter an object handle.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!