我有两个edittext框。我想在用户单击其他位置而不是这些edittext框时立即给出错误消息。我收到消息
参考不存在的字段' eth_xegim'。
事实上,在这两个之前我有几个edittext框。当我打印S
时,我可以看到字段名最多打印到xegim
但不打印xegim
S.fh = figure('Visible','on','numbertitle','off','Name','GUI',...
'units','pixels','Position',[50 50 1500 750]);
% Panel start
S.ph_arazi = uipanel('Parent',S.fh,'Title','Arazi','TitlePosition','centertop',...
'units','pixels','Position',[1180 364 300 244]);
S.sth_xegim = uicontrol(S.ph_arazi,'Style','text','String','x Eksenine gore egim [%]','HorizontalAlignment','left','Position',[10 68 130 18]);
% xegim edittext
S.eth_xegim = uicontrol(S.ph_arazi,'Style','edit','String','0',...
'HorizontalAlignment','right','BackgroundColor','w',...
'Position',[250 68 40 18],'callback',{@errmsg,S});
S.sth_yegim = uicontrol(S.ph_arazi,'Style','text',...
'String','y Eksenine gore egim [%]','HorizontalAlignment','left',...
'Position',[10 40 130 18]);
% xegim edittext
S.eth_yegim = uicontrol(S.ph_arazi,'Style','edit',...
'String','0','HorizontalAlignment','right',...
'BackgroundColor','w','Position',[250 40 40 18],...
'callback',{@errmsg,S});
% error message
function [] = errmsg(varargin)
S = varargin{3}
xegim = get(S.eth_xegim,'String');
xegim = xegim(ismember(xegim,'.:0123456789'));
yegim = get(S.eth_yegim,'String');
yegim = yegim(ismember(yegim,'.:0123456789'));
if isempty(xegim) || isempty(yegim)
if length(S.fh)==1
S.fh(2) = figure('numbertitle','off','Name','Error',...
'menubar','none','units','pixels',...
'Position',[700 400 200 100]);
S.sth_error = uicontrol(S.fh(2),'Style','text',...
'String','Girdiler sayi olmali!','Min',0,'Max',2,...
'BackgroundColor','r','Position',[10 10 180 80]);
ag = findobj;
nf = max(ag(find(ag==fix(ag))));
if nf == 2
close(S.fh(2))
end
S.fh(2) = [];
end
return;
end
答案 0 :(得分:1)
当您将S
添加到回调作为附加输入参数时,S
不包含字段eth_xegim
和eth_yegim
,因为它们尚未添加到结构体。在添加字段后定义回调:
S.eth_xegim = uicontrol(S.ph_arazi,'Style','edit','String','0',...
'HorizontalAlignment','right','BackgroundColor','w',...
'Position',[250 68 40 18]);
S.eth_yegim = uicontrol(S.ph_arazi,'Style','edit',...
'String','0','HorizontalAlignment','right',...
'BackgroundColor','w','Position',[250 40 40 18]);
S.eth_xegim.Callback = {@errmsg,S};
S.eth_yegim.Callback = {@errmsg,S};