var
I, Code: Integer;
begin
Val(Edit1.Text, I, Code);
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0);
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));
end;
I, Code: Integer;
begin
Val(Edit1.Text, I, Code);
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0);
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
function if_num(x:string):bool;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
//是数字组成的话返回true
function tform1.if_num(x:string):bool;
var i:integer;
begin
result:=true;
for i:=1 to length(x)do
if not(x[i] in ['0','1','2','3','4','5','6','7','8','9'])then result:=false;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if if_num(edit1.text) then showmessage('number');
end;end.
function Isnum(str: string): boolean;
var
ilen: integer;
i: integer;
begin
ilen := length(str);
result := true;
i := 1;
while i <= ilen do
begin
if not (str[i] in ['0'..'9', '-']) then
Break;
i := i + 1;
end;
if i <= ilen then
result := false;
end;
function TForm_LookupEDIT.isnum(str: string): boolean;
begin
result:=true;
try
strtofloat(str);//如果出错就说明不是数字
except
result:=false;
end;end;
var i:string;//假定是String;
try
floattostr(i);
inttostr(i);
except
showmessage('I isn't number!');
end;