procedure TFrm1.edtKeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9', Char(VK_BACK), Char(VK_DELETE), Char(VK_RETURN)]) then Key := #0; end;
首先设置Form的keypreview属性为true;在onkeypress中写:if ((not(key in ['0'..'9'])) or (key<>#8)) then begin key := #0; end;
procedure TFrm1.edit1KeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9','.','#13','#8']) then Key := #0; end;
var Key: Char);
begin
if not (Key in ['0'..'9', Char(VK_BACK), Char(VK_DELETE), Char(VK_RETURN)]) then
Key := #0;
end;
begin
key := #0;
end;
var Key: Char);
begin
if not (Key in ['0'..'9','.','#13','#8']) then
Key := #0;
end;