How can I edit an appdesigner's destructor

16 vues (au cours des 30 derniers jours)
Jack
Jack le 22 Mai 2019
Modifié(e) : RST le 14 Mar 2024
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!

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (1)

RST
RST le 5 Déc 2023
Modifié(e) : RST le 14 Mar 2024
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

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by