How can I edit an appdesigner's destructor

19 views (last 30 days)
Jack
Jack on 22 May 2019
Edited: RST on 14 Mar 2024 at 13:35
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!

Accepted Answer

Nathan Kueterman
Nathan Kueterman on 3 Sep 2019
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 Comments
Jack
Jack on 6 Sep 2019
Thank you very much! (If only I could now remember why I wanted to do that! :-P)
RST
RST on 28 Nov 2023
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.

Sign in to comment.

More Answers (1)

RST
RST on 5 Dec 2023
Edited: RST on 14 Mar 2024 at 13:35
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

Categories

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

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!