Result := True; try StrToInt(s); except showmessage('只能输入数字'); end;
Result := True; try StrToInt(s); except Result := False; end;if Result=true then ... else ...
function isfloat(txt: string):boolean; var i:integer;begin for i:=1 to length(txt) do if (txt[i] in ['0'..'9']) or (txt='.') then Result :=true else Result :=false;end; 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 Result :=false; end;
for i:=1 to length(txt) do if (txt[i] in ['0'..'9']) or (txt='.') then Result :=true else Result :=false; 这段代码还得考虑一个字符窜中出现两个以上的‘。’!
Indicates whether the specified variant represents a numeric value.Unit VariantsCategoryVariant support routinesDelphi syntax:function VarIsNumeric(const V: Variant): Boolean;DescriptionVarIsNumeric returns true if the given variant's type code indicates a numeric value of some sort. This can be either a floating-point value or an ordinal value. If the variant contains any other type of value, the function result is false.
TryStrToFloat TryStrToCurr TryStrToInt ...
try StrToInt(s); except Result := False; end;
function IsNumber(s: string): Boolean; var err: integer; v: integer; begin val(s, v, err); Result := err > 0; end;
你可以逐个取去字符串中的各个字符,进行判断 int i ; i :=0; while i <=Length(str) do if str[i] in ['0'..'9'] then inc(i) else showmessage('不是数字 ');
try
StrToInt(s);
except
Result := False;
end;
function IsDigit(ch: char): boolean;
begin
Result := ch in ['0'..'9'];
end;
function IsNumeric(c: char): Boolean;
(我在网吧,查不到,不过我记得delphi自己处理打开文件的.pas里就用过,自己看看)
try
StrToInt(s);
except
showmessage('只能输入数字');
end;
try
StrToInt(s);
except
Result := False;
end;if Result=true then ... else ...
var i:integer;begin
for i:=1 to length(txt) do
if (txt[i] in ['0'..'9']) or (txt='.') then Result :=true
else Result :=false;end;
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 Result :=false;
end;
对应事件:
try
StrToInt(s);
except
showmessage('请输入数值!');
end;
if (txt[i] in ['0'..'9']) or (txt='.') then Result :=true
else Result :=false;
这段代码还得考虑一个字符窜中出现两个以上的‘。’!
TryStrToCurr
TryStrToInt
...
StrToInt(s);
except
Result := False;
end;
var
err: integer;
v: integer;
begin
val(s, v, err);
Result := err > 0;
end;
int i ;
i :=0;
while i <=Length(str) do
if str[i] in ['0'..'9']
then inc(i)
else showmessage('不是数字 ');
2、利用ascii码判断