大概有两种方法: 1、 如上说的try... except 的结构 2。在edit1的OnKeyPress事件中写代码 if key in ['0','1','2','3','4','5','6','7','8','9'] then else Abort
这样吧,在form的public里设两个boolean型变量,IsChar和IsInt; 在Edit 的keypress里 IsChar:=false; IsInt:=false; if (key in ['a'..'z'])or(key in ['A'..'Z']) then IsChar:=true; if (key in[0..9])then IsInt:=true; 然后在需要的地方再判断这两个变量的值就行了.;
if key in ['0','1','2','3','4','5','6','7','8','9'] then IsInt:=true; else IsInt:=false;
if (edit1.text>='000000000000000000000') and (edit1.text>='9999999999999999999')
TheTop(黄河上游) 的有道理!也可行!
if key in ['0','1','2','3','4','5','6','7','8','9','.'] then IsInt:=true; else IsInt:=false;不遥忘了小数点 13.5也是数字哦
上面的全部都是蠢猪: if IsNumeric(char(edit1.text)) then showmessage('非字符串'); else showmessage('字符串');
字符
else
数字
1、 如上说的try... except 的结构
2。在edit1的OnKeyPress事件中写代码
if key in ['0','1','2','3','4','5','6','7','8','9'] then
else Abort
在Edit 的keypress里
IsChar:=false;
IsInt:=false;
if (key in ['a'..'z'])or(key in ['A'..'Z']) then IsChar:=true;
if (key in[0..9])then IsInt:=true;
然后在需要的地方再判断这两个变量的值就行了.;
else IsInt:=false;
else IsInt:=false;不遥忘了小数点 13.5也是数字哦
if IsNumeric(char(edit1.text)) then
showmessage('非字符串');
else showmessage('字符串');
标准方法是用val,你可以在程序里写个val,在上面按F1看delphi的帮助,很详细的,还有例子。