如题!!
解决方案 »
- delphi操作advstringgrid问题,新手。
- indy10 的问题。
- 修改 通过输入的信息 输出时间差
- 兄弟们怎样来检测数据库里面的一个表是否存在?不是在数据库里检测在软件中如何检测?
- 100分求asp解码器问题
- 为什么我做的邮件发送程序发163.com总是不成功(有通过身份验证的),但发Sohu.com和21cn.net,和21cn.com就行请问这是什么问题,赋上源程序请
- 关于句柄,来就给分
- 想认识珠海写Delphi的朋友
- 高分求助如何在msagent的提示中插入按钮,文本框,超链接。
- 如何使DBGRID的 当前记录以反色显示?
- 编程=?梦想、成就、事业
- 小弟准备学习编程,求救.......
begin
if Key in ['0'..'9',#8,#13] = False then
begin
Application.MessageBox('只能输入数字! ','系统提示',MB_OK+MB_ICONWARNING);
Edit1.SetFocus;
Abort;
end;
end;
//至于小数点,可以自己加控制
begin
if not(key in [#48..#57,#46]) then
Key := #0;
end;
try
strtofloat(edit1.text);
except
edit1.text:='0';
end
begin
if not (key in ['0'..'9','.',#8]) then
key:=#0
end;
const NumberSet = ['0' .. '9', char(#8), char(#13), char(#46), '.', '-'];
begin
if not (Key in NumberSet) then Key := #0;
if (Key = '.') and ((Length(AStr) = 0) or (Pos('.', AStr) > 0)) then
Key := #0; if (Length(AStr) = 1) and (AStr[1] = '0') and (Key = '0') then Key := #0;
Result := Key <> #0
end;你可以在OnKeyPress中调用
begin
if not (key in ['0'..'9','.',#13,#8]) then key:=#0
//只能用数字,".",回车(#13),退格(#8)
end;
只是可以在这个EDIT中粘贴带有别的字符的东东
begin
if not (key in['0'..'9',#8]) then
begin
key:=#0;
messagebeep(1);
application.MessageBox('请输入数字!','提示!',mb_ok+mb_iconwarning);
end;
end;
这样就可以实现了
try
strtofloat(edit.text);
except
showmessage('error');
edit.setfocus;
end;还有就是在EDIT的ONKEYPRESS里添加对KEY的判断
if not (key in ['0'..'9','.',#8,#13]) then
key:=0;上面这个写法有问题的,就是无法控制小数点的位置和个数.
所以在EDIT失去焦点的时候判断一下是很有必要的.除非你把错误的可能都排除了,禁止EDIT粘贴之类的,老问题了啊.期待高手写个这样EDIT的控件吧.呵呵,最好是免费的哦