How can I edit an appdesigner's destructor

18 次查看(过去 30 天)
I'm using appdesigner for the first time, and like the way in which it combines an interface similar to a modern IDE with OO code
However, I'd like to edit the destructor of the class, in particular to call the destructors of its child windows (themselves other appdesigner apps, between which I pass data) which otherwise is not done. The region of text is just greyed out in the window. Any ideas?
Thank you!

采纳的回答

Nathan Kueterman
Nathan Kueterman 2019-9-3
In the Editor tab, top left there is a add callback button. Click this then for component dropdown choose your main window. Callback dropdown choose the close request function. Insert your custom destructor code in the code block it generated. (Took me a few weeks to discover where this was hidden)
  2 个评论
Jack
Jack 2019-9-6
Thank you very much! (If only I could now remember why I wanted to do that! :-P)
RST
RST 2023-11-28
Beware that the <main figure>CloseRequest(app, event) function is not called when the app is simply delete() -ed . This is addressed in this Stackoverflow article.
Having defined the CloseRequest function it is possible to call (for example)
close( myApp.UIFigure )
but this still does not help if the app is deleted by any other means.
This is for R2020a and possibly others.

请先登录,再进行评论。

更多回答(1 个)

RST
RST 2023-12-5
编辑:RST 2024-3-14
Given that the CloseRequest() function is is not called when an app is delete()-ed, I believe the most reliable solution is to listen to the UIFigure's ObjectBeingDeleted event.
This is only a bit more complicated than completing code in a callback. And better than trying to manually close() all the apps as i suggest in my comment, above.
.
.
.
methods (Access = private)
% code to run before app is destroyed
function onBeingDestroyed( app, src, evtdata) %#ok<INUSD>
% my cleanup code here
end
end % private methods
.
.
.
% Code that executes after component creation
function startupFcn(app)
% listen to my ObjectBeingDestroyed event
addlistener(app, ...
'ObjectBeingDestroyed', @app.onBeingDestroyed);
end

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by