限制为只接收数字:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not(key in['0'..'9',#8])then
begin
key:=#0;
MessageBeep(1);
end;
end;
限制编辑框只接收字母(不管大小写)输入:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not(key in['a'..'Z',#8])then
begin
key:=#0;
MessageBeep(1);
end;
end;