Only number in TEdit, Delphi
问题 How can I add a TEdit that only accept numbers? I search information but nothing helps me. I need a TEdit that does not accept any letter or strings. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (Key in [#8, '0'..'9', DecimalSeparator]) then begin ShowMessage('Invalid key: ' + Key); Key := #0; end else if (Key = DecimalSeparator) and (Pos(Key, Edit1.Text) > 0) then begin ShowMessage('Invalid Key: twice ' + Key); Key := #0; end; end; 回答1: In modern Delphi