function IsNumberStr(mStr: string): Boolean; var I: Integer; begin Result := False; for I := 1 to Length(mStr) do if not (mStr[I] in ['0' .. '9']) then Exit; Result := True; end;
function IsNumber(mStr: string): Boolean; var I: Real; //IsInteger() -> I: Integer; E: Integer; begin Val(mStr, I, E); Result := E = 0; end;
function IsNumberStr(mStr: string): Boolean; var I: Integer; begin Result := False; for I := 1 to Length(mStr) do if not (mStr[I] in ['0' .. '9']) then Exit; Result := True; end;
strtoFloat('23423');
except
showmessage('error');
end;
var
I: Integer;
begin
Result := False;
for I := 1 to Length(mStr) do
if not (mStr[I] in ['0' .. '9']) then
Exit;
Result := True;
end;
var
I: Real; //IsInteger() -> I: Integer;
E: Integer;
begin
Val(mStr, I, E);
Result := E = 0;
end;
strtoint('23423');
except
showmessage('error');
end;
否则就VSaber(☆浪人☆)等的方法。
TryStrToInt()
TryStrToFloat()
TryStrToDate()
TryStrToTime()
TryStrToBool()
//............
var
I: Integer;
begin
Result := False;
for I := 1 to Length(mStr) do
if not (mStr[I] in ['0' .. '9']) then
Exit;
Result := True;
end;
用 Val 函数即可,你可以查查帮助就应该知道怎么用了。