How can I edit an appdesigner's destructor

17 ビュー (過去 30 日間)
Jack
Jack 2019 年 5 月 22 日
編集済み: RST 2024 年 3 月 14 日
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 Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by