procedure TForm1.Button1Click(Sender: TObject);
var
temp : string;
i : integer;
begin
temp := Edit1.Text;
for i := 1 to Length(Temp) do
if ((ord(temp)< 48) or (ord(temp) > 57)) then
begin
Edit2.Text := ' 在您输入的数字中夹杂其他字符。';
exit;
end
else
Edit2.Text := ' 您所输入的数字正确。'
end;
procedure TFmainin.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
//用RETURN=TAB
if key=#13 then
begin
key:=#0;
perform(CM_DialogKey,VK_TAB,0);
end
else
//只输与数据有关的键
begin
if not (key in['-','0','1','2','3','4','5','6','7','8','9','.',#8]) then
begin
key:=#0;
beep;
edit1.exit;
end;
end;
end;
其中#8是退格(删除)键