如何让Edit控件只能接受数字和小数点,并且小数点只能有一个?if not (key in['0'..'9','.',#8]) then
key:=#0
else if key in['.'] then
begin
{这段代码如何写呢?}
end;
key:=#0
else if key in['.'] then
begin
{这段代码如何写呢?}
end;
解决方案 »
- fastreport 如何实现垂直band
- 在treeview里加了个右键菜单,结果第一个按钮没问题,第二个只要一输入不管什么都是 unable to invoke code completion due to errors
- 一个窗体调用问题?
- 遇到一个麻烦的问题,请高手给个思路!
- 大侠们!帮我看看这段代码哪里错了?在线急等。。。
- FastReport怎么跟数据库连接?
- 一个老菜鸟的问题
- 急,急,急关于delphi与后端数据库sql连接的问题,若能解决,给200分
- 求救,Grid++Report4.0 的问题!
- adoquery的DeleteRecords()命令应怎么用?
- Delphi中处理word文档与数据库的互联问题,急!!!!!分不够在加
- 怎么传递一个过程?
begin
if Kind = '整数' then
begin
if Key in ['0'..'9',#13,#8] = False then
begin
Application.MessageBox('只能输入整数! ','系统提示',MB_OK+MB_ICONWARNING);
Edit.SetFocus;
Abort;
end;
end
else if Kind = '小数' then
begin
if (Trim(Edit.Text) = '')and(Key = '.') then
begin
Application.MessageBox('小数格式输入有误! ','系统提示',MB_OK+MB_ICONWARNING);
Edit.SetFocus;
Abort;
end;
if (Pos('.',Trim(Edit.Text)) > 0)and(Key = '.') then
begin
Application.MessageBox('小数格式输入有误! ','系统提示',MB_OK+MB_ICONWARNING);
Edit.SetFocus;
Abort;
end;
if Key in ['0'..'9','.',#13,#8] = False then
begin
Application.MessageBox('只能输入小数! ','系统提示',MB_OK+MB_ICONWARNING);
Edit.SetFocus;
Abort;
end;
end;
end;
Edit1.Text:=FormatFloat('0.0',StrToFloat(Edit1.Text));
Except
Application.MessageBox('请正确输入数据','提示',Mb_OK);
End;
控件就可以了.在 Additional 组件页内
var PointFlag:Boolean;
begin
PointFlag:=false;
...
else if key in ['.'] then
if PointFlag then key:=#0
else PointFlag:=true;其中PointFlag也可以设置为Integer,用0或1表示是否出现了小数点
for i:=1 to length(trim(edt_sjje.Text)) do
begin
str:=midstr(trim(edt_sjje.Text),i,1);
if(str='.')or((str>='0')and(str<='9'))then
begin
ffbz:=true;
end
else begin
showmessage('你输入了非法字符,请重新输入。');
ffbz:=false;
break;
end;
end;
if ffbz then
begin
//在这里无须其他只需要转换一下strtofloat(edit1.text)
end;