function IsNumber(s:string):integer; var i : integer; begin result := 2; for i := 1 to Length(s) do begin if (s[i] < '0') or (s[i] > '9') then begin if (s[i] = '.') and (i <> 1) and (i <> Length(s)) then begin if result = 1 then begin result := 2; Exit; end; result := 1; continue; end; exit; end; end; if result <> 1 then result := 0; end;返回 0 -- integer 1 -- double 2 ---string
try
StrToInt(Edit1.Text);
except
ShowMessage('该值不是数字');
end;
var
i : integer;
begin
result := 2;
for i := 1 to Length(s) do
begin
if (s[i] < '0') or (s[i] > '9') then
begin
if (s[i] = '.') and (i <> 1) and (i <> Length(s)) then
begin
if result = 1 then
begin
result := 2;
Exit;
end;
result := 1;
continue;
end; exit;
end;
end;
if result <> 1 then result := 0;
end;返回 0 -- integer 1 -- double 2 ---string