what's the difference between handles and hObject?

6 visualizaciones (últimos 30 días)
John Bitzios
John Bitzios el 2 de Oct. de 2014
Comentada: Sean de Wolski el 3 de Oct. de 2014
Where do I use handles and hObject?? And why are there function which contain sometimes both of them plus eventdata and other one of those 3 is missed?? for example function pushbutton1_Callback(hObject, eventdata, handles)

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 2 de Oct. de 2014
hObject is the handle to the calling object; i.e. the object that is calling the function. handles is a structure with all of the handles to all objects.
The only time I use hObject is if I have two objects sharing a callback, e.g. pushbutton1 and pushbutton2 both call foo_Callback. In this scenario, I would use hObject to determine which one called or if we needed to modify the calling object.
  2 comentarios
John Bitzios
John Bitzios el 3 de Oct. de 2014
Editada: John Bitzios el 3 de Oct. de 2014
If you put all of them for example function mygui(hObject,handles,eventdata) and you might use only the hObject without any handles or eventdata, is there gonna be a problem??
Sean de Wolski
Sean de Wolski el 3 de Oct. de 2014
No, it's just an extra variable. If you don't need them, you can deny them with a tilde
mygui(hObject,~,~)

Iniciar sesión para comentar.

Más respuestas (1)

Iain
Iain el 2 de Oct. de 2014
handles is a structure holding ALL of the handles for the GUI.
hObject, is JUST the handle for the GUI object used.
eventdata contains specific event data - like what cell got selected on a table/what key got pressed.
  1 comentario
John Bitzios
John Bitzios el 3 de Oct. de 2014
If you put all of them for example function mygui(hObject,handles,eventdata) and you might use only the hObject without any handles or eventdata, is there gonna be a problem??

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by