小弟需要文本框中只显示数字,写得一个相关函数。用异常来判断,为什么运行到strtoint(numstr);时,Delphi本身发出error,我写得异常处理要在关闭这个error提示才能运行,请高手看看是否有问题,谢谢!!!!!!
function tform5.isStrANumber(NumStr:string):boolean;
begin
result:=true;
try
strtoint(numstr);
except
on EConvertError do
result:=false;
end;
end;
function tform5.isStrANumber(NumStr:string):boolean;
begin
result:=true;
try
strtoint(numstr);
except
on EConvertError do
result:=false;
end;
end;
begin
result:=true;
try
strtoint(numstr);
exceptend;
end;
begin
if (key > '9') or (key < '0') then
if key <> #8 then
key := #0;
end;
var i:integer;
begin
result:=true;
for i:=0 to length(numstr) do
if not (numstr[i] in ['0','1','2','3','4','5','6','7','8','9']) then
begin
result:=false;
break;
end;
end;
Function IsNumber(Str:String) : integer;
var
XSD , i : integer;
cTmp : String;
begin
if (Str='') or (Str='+') or (Str='-') then begin Result := 0; exit ; end;
XSD := pos('.',Str);
if XSD >0 then Result := 1 else Result := 2;
for i:=1 to length(Str) do begin
cTmp :=copy(Str,i,1);
if ((cTmp ='+') or (cTmp='-')) and (i>1) then Result := 0;
if (cTmp='.') and (XSD<>i) then Result := 0;
if (pos(cTmp,'+-0123456789.')<1) then Result := 0;
end;
end;
begin
result:=true;
try
strtoint(numstr);
except
result:=false;
end;
end;
begin
result:=true;
try
strtoint(numstr);
except
result:=false;
end;
end;