function TryStrToInt(const S: string; out Value: Integer): Boolean;
function isint(txt: string):boolean; var i:integer;begin for i:=1 to length(txt) do if (txt[i] in ['0'..'9']) then Result :=true else begin Result :=false; exit; end; end;
var E: Integer; begin Val(S, Result, E); if E <> 0 then//非数字 Result := Default;
uses IdGlobal; function TForm1.StrIsNumber( str : String) : Boolean; var p : pchar; i : integer; c : char; strVal,strTemp : string; begin strVal := Trim(str); if Length(strVal)<=0 then begin Result := False; exit; end; for i := 0 to length(strVal) - 1 do begin p := Pchar(strVal); c := p[i]; if not IsNumeric(c) then begin SetLength(strTemp,1); strTemp :='.'; if strTemp <> c then begin Result := False; exit; end; end; end; Result := True; end;
你的数字是什么类型的数字?是整型?浮点型还是其他?不如自定义一个函数,如: Function JudgeStrIfData(const S:String; var value:float):Boolean; var fl:float; temp:boolean; begin temp:=false;
var i:integer;begin
for i:=1 to length(txt) do
if (txt[i] in ['0'..'9']) then Result :=true
else
begin
Result :=false;
exit;
end;
end;
E: Integer;
begin
Val(S, Result, E);
if E <> 0 then//非数字
Result := Default;
function TForm1.StrIsNumber( str : String) : Boolean;
var
p : pchar;
i : integer;
c : char;
strVal,strTemp : string;
begin
strVal := Trim(str); if Length(strVal)<=0 then
begin
Result := False;
exit;
end; for i := 0 to length(strVal) - 1 do
begin
p := Pchar(strVal);
c := p[i];
if not IsNumeric(c) then
begin
SetLength(strTemp,1);
strTemp :='.';
if strTemp <> c then
begin
Result := False;
exit;
end;
end;
end; Result := True;
end;
Function JudgeStrIfData(const S:String; var value:float):Boolean;
var
fl:float;
temp:boolean;
begin
temp:=false;
try
fl:=strtofloat(trim(s));
value:=fl;
temp:=true;
except
end;
result:=temp; end;
strtofloat(trim(s));
showmessage('数字。');
except
showmessage('不是数字。');
end;
exceptend