Referencing GUI object in function

2 Ansichten (letzte 30 Tage)
Scott Rodriguez
Scott Rodriguez am 29 Mai 2018
Kommentiert: Geoff Hayes am 29 Mai 2018
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 Kommentare
Image Analyst
Image Analyst am 29 Mai 2018
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 am 29 Mai 2018
Maybe the function FrameCallback(sender,args) is called by the DLL (somehow)?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 29 Mai 2018
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 Kommentar
Scott Rodriguez
Scott Rodriguez am 29 Mai 2018
Bearbeitet: Scott Rodriguez am 29 Mai 2018
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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by