Deleting CreateFcn from GUI .m file

I have finished creating GUI and since I have a lot of objects my .m-file is quite long, mainly because there is a lot of
function name_CreateFcn(hObject, eventdata, handles)
I thought I can delete these CreaterFcn since I dont use then, only Callbacks, but when I deleted them and run the program I am receiving an error for each object:
Error using feval Undefined function 'name_CreateFcn' for input arguments of type 'matlab.ui.control.UIControl'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in GUI (line 16) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI('name_CreateFcn',hObject,eventdata,guidata(hObject))
Is it possible then to delete these CreateFcn without receiving error, or they must remain in the code?

 Respuesta aceptada

Adam
Adam el 5 de Sept. de 2016

1 voto

Yes, you can delete them, and I almost always do, but you must also clear the field in the corresponding graphics object within GUIDE.
So you will find a CreateFcn property field and you can just delete what is in here.
I also do the same thing for the Callback property field in cases where I do not want a callback.

6 comentarios

Jakub F
Jakub F el 5 de Sept. de 2016
Thank you
Arnab Das
Arnab Das el 2 de En. de 2018
Thanks a lot.
Anand Parikh
Anand Parikh el 28 de Nov. de 2018
When i try to delete "function name_CreateFcn(hObject, eventdata, handles)" in the Create_Fcn field in GUIDE , then it automatically comes back and i do not get it deleted.
Is there any solution to that?
luke12cz
luke12cz el 29 de Nov. de 2018
@Anand Parikh: Press 'Enter' after deleting the whole line in the property inspector (don't just mouse-click out of the row). Only then you can close the window of the inspector and have the change in effect. Later when you save the .fig file from GUIDE, it will be written out correctly.
付 凡
付 凡 el 18 de Mayo de 2022
Thanks a lot!
Voss
Voss el 18 de Mayo de 2022
There is an option in GUIDE (in the Tools menu > GUI Options ...) called "Generate callback function prototypes", which is selected by default. De-selecting this option will prevent CreateFcns and Callbacks from being generated in the first place.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Sept. de 2016

Comentada:

el 18 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by