delphi中怎么样让五个edit框之合只能是100
还有,只能输入数字
还有,只能输入数字
解决方案 »
- 请教delphi中的type自定义类型在什么地方定义,我怎么找不到
- 利用mshtml得到了某个IHTMLElement的实例,但是如何获得这个实例的width呢?
- 请教一个问题:如何用编程的方式修改AVI文件的标题\作者\等信息(Delphi)
- 遇到这方面问题,不知道怎么弄,希望高手指点!解决马上结贴,失言小狗!
- 求救!!!
- 请问用Insert时values为变量怎么写才正确?
- Illegal character in input file:' '($A1A1) 是什么错误啊?
- 请教TWinSocketStream传送文件方法
- 如何拦截WM_NCLBUTTONDBLCLK消息?(帖子有问题了,重新发)
- 哪位高手可以告诉我如何制作类似Qicq隐藏显现窗体的功能?(上下方向)
- 为何我DBEdit在运行时不能编辑???
- GetTickCount函数的功能是什么?
if key in['0'..'9',#8] then
edit1.readonly:=False
else
readonly:=True;
或者先随便输,在确定的时候做校验就可以了!
begin
...
end;orEdit5.Text := 100 - (strtofloat(edit1.text)+strtofloat(edit2.text)+strtofloat(edit3.text)+strtofloat(edit4.text));2、onexit里写事件
try
strtofloat(edit1.text);
except
showmessage('只能输入数字');
end;
if StrToInt(Edit1.Text)+StrToInt(Edit2.Text)+StrToInt(Edit3.Text)+
StrToInt(Edit4.Text)+StrToInt(Edit5.Text)<>100 then
ShowMessage('和只能是100');
except
ShowMessage('只能输入整数');
exit;
end;
第二个问题:用maskedit控件,或者在edit1的keypress里写
if not(key in['0'..'9',#8]) then key:=#0;
var
i : Integer;
i := strtoint(edit1.text)+strtoint(edit2.text)+strtoint(edit3.text)+
strtoint(edit4.text)+strtoint(edit5.text);
if i <> 100 then
begin
end;2.
procedure T_Form.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
if not (key in ['0'..'9']) then begin
key := #0;
ShowMessage('输入的不是数字');
end;
end;
然后,因为五个数加起来是100,设五个edit数字分别是a,b,c,d,e。所以,a最大只能是100-4=96。b最大只能是100-3-a,c最大只能是100-2-a-b,d最大只能是100-1-a-b-c,e也就随之确定。
以上都在edit的OnExit事件里判断。