Borrar filtros
Borrar filtros

How can I edit an appdesigner's destructor

15 visualizaciones (últimos 30 días)
Jack
Jack el 22 de Mayo de 2019
Editada: RST el 14 de Mzo. de 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!

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

RST
RST el 5 de Dic. de 2023
Editada: RST el 14 de Mzo. de 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

Categorías

Más información sobre App Building en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by