Skip to main content
1 of 4
Marcodor
  • 5.9k
  • 1
  • 27
  • 26

It's better to put your allow keys in a set as a constant (speed, optimization):

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); const AllowKeys: set of Char = [#48..#57, #46, #8]; begin if not (Key in AllowKeys) then begin ShowMessage('Invalid key: ' + Key); Key := #0; end; end; 

#8 here is your backspace, #48-#57 - digits

Marcodor
  • 5.9k
  • 1
  • 27
  • 26