Need to test the validity of an application handle

조회 수: 11 (최근 30일)
Richard
Richard 2023년 3월 23일
편집: Adam Danz 2023년 3월 24일
I call a data application from my main application and store the data app handle in a main app local variable.. The data app has a Close button which first sets the handle to [] (by using the callingApp handle and then deletes itself. This works fine, no problem.
The probem occurs when the user closes the data app window using the "X" in the upper r/h corner. This action does execute the delete callback, but I'm unable to add code to this callback to also empty the data app handle. I'd prefer the user not use the "X", but it's impossible to prevent him from doing so inadvertently.
Isvalid would do the trick, but it's not available in 2022b. I could upgrade to 2023a, but I'd prefer not doing so at this time. An solutions?

채택된 답변

Adam Danz
Adam Danz 2023년 3월 23일
편집: Adam Danz 2023년 3월 24일
> I'd prefer the user not use the "X", but it's impossible to prevent him from doing so inadvertently.
You can set the [x] close button to be unresponsive to clicks.
uif = uifigure('CloseRequestFcn',[])
Or display an alert box to inform the user to use the app's close button
uif = uifigure('CloseRequestFcn',@(f,~)uialert(f,'Use the app''s close button','No-Can-Do'))
To close these figures
close(uif,'force')
% or
delete(uif)
or, if you lose the handle, this deletes all figures
close all force
  댓글 수: 1
Richard
Richard 2023년 3월 24일
I thought there might be a callback for the "X", but wasn't able to find it. That will do the trick.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 3월 24일
Isvalid would do the trick, but it's not available in 2022b.
isvalid with lower-case I has been available since at least 2006.
  댓글 수: 2
Richard
Richard 2023년 3월 24일
편집: Richard 2023년 3월 24일
I can't look at the code from this computer, but I know I've tried lower case without succes. I didn't realize there was an upper case function elsewhere in the various toolboxes. The "Isvalid" in my original question is only capitalized due to force of habit.
Below is the error I receive in 2022B with the correct lower case.
'isvalid' requires one of the following:
Industrial Communication Toolbox
Image Acquisition Toolbox
Instrument Control Toolbox
Error in W3DPlot/UIAxesButtonDown (line 668)
if ~isvalid(app.hWdataPoint)
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating UIAxes ButtonDownFcn.
Walter Roberson
Walter Roberson 2023년 3월 24일
I am running R2022b. isvalid() exists in a large number of methods, including handle class; https://www.mathworks.com/help/matlab/ref/handle.isvalid.html
If it is telling you that you need one of those toolboxes, we might guess that whatever app.hWdataPoint is is not a handle. What shows up for class(app.hWdataPoint) at that point ? And ishandle(app.hWdataPoint) and isa(app.hWdataPoint, 'handle') ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by