在onchengh事件中,btnok.enable := (edit1.text<>'') and (edit2.text <> '');
补充 你要当所有的EDIT都输入完的话 要这样做 你的每个EIDT控件的KEYPRESS事件中加入下面代码就行了 procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); var i,flag1:integer; begin for i:=1 to 2 do //n为你的EDIT的个数 begin if tedit(form1.findcomponent('edit'+inttostr(i))).text='' then begin flag1:=1; end; end; if flag1<>1 then begin button1.enabled:=true; end; end;
呵呵,换个思路,加一个timer,然后响应其事件var iIndex: Integer; begin for iIndex := 0 to ComponentCount - 1 do begin if Components[iIndex] is TEdit then begin if TEdit(Components[iIndex]).Text='' then continue else abort; end; end; button1.enable:=true; timer1.enable:=false;
end;
to l_xiaofeng(流水不腐) 好我说清楚点 我先说说你的问题,看我理解的对不对 你的form里有n(n>=10)个edit,还有一个button 你想让所有的edit里都有值button.enable:=true; 有一个edit是空的那么button.enable:=false;解决办法 先在form上加个控件actactionlist1是TActionlist类的 这个控件在standard页上的最右边的控件 双击它然后new一个action,取名actok 在actok的onupdate事件中写代码procedure TFrmLogin.actokUpdate(Sender: TObject); var i:integer; ok:boolean; begin ok:=true; for i:= 0 to frmlogin.ComponentCount - 1 do begin if frmlogin.Components[i] is TEdit then begin if (Components[i] as TEdit).Text='' then begin ok:=false; break; end else ok:=true; end; actok.enable:=ok; end;最后在哪个属性监视器中把哪个button的action设成actok 注意啊button的caption会变成actok的caption 这就好拉程序都有拉 这样就一劳永逸了,有多少edit都不怕, 可以给分么? 想要action的讲解在问,不过别忘了给分 偶我的form的名称是frmlogin你看着改成你的form
呵呵,换个思路,加一个timer,然后响应其事件var iIndex: Integer; begin for iIndex := 0 to ComponentCount - 1 do begin if Components[iIndex] is TEdit then begin if TEdit(Components[iIndex]).Text<>'' then continue else abort; end; end; button1.enable:=true; timer1.enable:=false;
只用写一个事件,其它的指向它就可以了
就是说当EDIT有输入时BUTTON的ENABLED为TRUE吧
不然你要怎么判断它是不是已经输入完成呢
如果是我说的意思
那么你可以在EDIT的ONKEYPRESS事件中写入
BUTTON。SETFOCOUS;
就行了
给分吧:)
分无希多,
有分则行
and (edit2.text <> '');
你要当所有的EDIT都输入完的话
要这样做
你的每个EIDT控件的KEYPRESS事件中加入下面代码就行了
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
var i,flag1:integer;
begin
for i:=1 to 2 do //n为你的EDIT的个数
begin
if tedit(form1.findcomponent('edit'+inttostr(i))).text='' then
begin
flag1:=1;
end;
end;
if flag1<>1 then
begin
button1.enabled:=true;
end;
end;
那么这样试试,在某一个edit的onexit里写
button1.enabled :=
((edit1.text<>'')and(edit2.text<>'')and....);
有点麻烦哈,也可以遍历form上所有的edit。当然每个edit的onexit都要指向这个事件了。
在action的update时间中判断所有的edit是否都添了,然后设置action的enable
在把button的action设成action就ok了
楼主怎么还不结帖啊
我用的方法是在每个EDIT里面都添代码。
楼上的意思就是不用这样做也可以?
可否告诉我详细的怎么做,如果想要分告诉我
我可以另开帖子给分,谢谢!
iIndex: Integer;
begin
for iIndex := 0 to ComponentCount - 1 do begin
if Components[iIndex] is TEdit then begin
if TEdit(Components[iIndex]).Text='' then continue
else abort;
end;
end;
button1.enable:=true;
timer1.enable:=false;
end;
好我说清楚点
我先说说你的问题,看我理解的对不对
你的form里有n(n>=10)个edit,还有一个button
你想让所有的edit里都有值button.enable:=true;
有一个edit是空的那么button.enable:=false;解决办法
先在form上加个控件actactionlist1是TActionlist类的
这个控件在standard页上的最右边的控件
双击它然后new一个action,取名actok
在actok的onupdate事件中写代码procedure TFrmLogin.actokUpdate(Sender: TObject);
var i:integer;
ok:boolean;
begin
ok:=true;
for i:= 0 to frmlogin.ComponentCount - 1 do
begin
if frmlogin.Components[i] is TEdit then
begin
if (Components[i] as TEdit).Text='' then
begin
ok:=false;
break;
end
else ok:=true;
end;
actok.enable:=ok;
end;最后在哪个属性监视器中把哪个button的action设成actok
注意啊button的caption会变成actok的caption
这就好拉程序都有拉
这样就一劳永逸了,有多少edit都不怕,
可以给分么?
想要action的讲解在问,不过别忘了给分
偶我的form的名称是frmlogin你看着改成你的form
button.onclick就可以不写拉
当你click button直接就执行actok.onexecute
别忘了把button的action设到actok上啊
其实action这个控件主要就是设置enable的,而且是为了
统一界面的,如果还有个菜单和这个button是一样的功能,
你也把菜单的action设上actok就可以了
我可说了不少
累!!
呵呵祝大家进步!!
iIndex: Integer;
begin
for iIndex := 0 to ComponentCount - 1 do begin
if Components[iIndex] is TEdit then begin
if TEdit(Components[iIndex]).Text<>'' then continue
else abort;
end;
end;
button1.enable:=true;
timer1.enable:=false;
end;