Referencing GUI object in function

2 次查看(过去 30 天)
Totally new to MatLab and OO programming, but I do know C quite well.
Was given a MatLab app code with GUI to put some finishing touches on. I've successfully worked with the GUI, referenced objects, updated stuff on the GUI and code successfully for a week now, so basically I know my way around. What's stumping me is: I have a function that was created by the vendor, but it's buried in a dll so I can't change the parameters to pass from the GUI into the function directly.
What I'm doing: I created a Static Text object in the GUI with the tag ' _ storing_'. It sits inside a uipanel1, and that inside my only figure named Figure. I want to change the static text's item's text string when something code-wise happens.
Below is the basic premise and error thrown. I've seen where lots of people have asked the same type question, I've tried at least a dozen recommended code solutions to reference the GUI object inside the vendor function without success.
I get what's happening, the object is outside the scope of the function, I just can't seem to figure out the MatLab calls to allow me to how to pass the object's handle inside the function to update the text. Can someone help please?
% --- NOT MY FUNCTION
function FrameCallback(sender,args)
try
if (thisExecutesOk)
% ...some stuff happens. The item is initially not visible so I try to turn it on. This is where it throws an error...
set(handles.storing,'visible','on'); % It jumps to 'catch' so the next line never gets called
set(handles.storing,'string',strcat('Storing... ',num2str(getFrameCounter-1))); % This works fine outside of the function
end
catch E
msg = E;
end
Error thrown is:
%
  6 个评论
Image Analyst
Image Analyst 2018-5-29
But we still have the problem of getting GUI parameters/settings into "a function that was created by the vendor, but it's buried in a dll so I can't change the parameters". How is this DLL going to find out about the values if it doesn't let you set them?
Geoff Hayes
Geoff Hayes 2018-5-29
Maybe the function FrameCallback(sender,args) is called by the DLL (somehow)?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2018-5-29
I don't understand. Is FrameCallback(sender,args) your function or not, or if it's not your function but do you have the source code for it? It seems like you have it because you proposed some changed code for the inside of that function.
Anyway, what does that code have to do with some DLL that you're calling? If you're using loadlibrary() to load some vendor's DLL so that you can call it, then what does that have to do with FrameCallback()?
Anyway, it should work as long as you have a control called storing and you have access to handles. Either pass handles in to FrameCallback()
function handles = FrameCallback(handles, sender, args)
or try to find it using the code Geoff gave you. If you don't want to pass handles back out, you can call guidata() to update it instead.
Then you can use modern OOP syntax like this:
handles.storing.Visible = 'on';
handles.storing.String = sprintf('Storing %d.', getFrameCounter-1);
Anyway, I don't think any of that will help you with setting parameters internal to the DLL that are not exposed and you're not able to set by passing values into the DLL for them, because, as you say "it's buried in a dll so I can't change the parameters to pass". If the DLL is not willing to let you send in new values, then you are probably out of luck.
  1 个评论
Scott Rodriguez
Scott Rodriguez 2018-5-29
编辑:Scott Rodriguez 2018-5-29
IA, thanks for the reply. I do have the code definition but do not have access to the declaration, so I can't change the parameter set to pass the GUI's handles. I assumed it was buried in one of the many dll's provided by Fluke, I could be wrong. This is an example of how the function is being called as a parameter of another Fluke-proprietary function inside the MatLab app:
Fluke.Thermography.IRAccess.Streaming.StreamSource.Instance.UnregisterFrameCallback(@FrameCallback);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by