如果要求输入的是整数
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.Handle, GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
end;
如果要输入小数的话
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var p:integer; tp:TPoint;
begin
if key in ['0'..'9','+','-','.'] then
begin
if key in ['+','-'] then
begin
p:=pos('+',Edit1.Text)+pos('-',Edit1.Text);
if p>0 then key:=#0
else
begin
GetCaretPos(tp);
if tp.x>1 then key:=#0;
end;
end
else
if key='.' then
begin
p:=pos('.',Edit1.Text);
if p>0 then key:=#0;
end;
end
else if key>#31 then key:=#0;
end;