Restrict Key Strokes in a TEdit Box

When you are asking a user to type a numerical value in a TEdit box, you may want to restrict the characters allowed. If for example you want to read an integer you will not allow any other character to be read. You need to edit key strokes as they are entered. To do this double click on the TEditBox KeyPress event to create an event handler (as shown below). If any key other than an integer or the backspace key ('/b') and the delete key (8) are pressed the key is set to 0 and no action takes place. If you were entering a double value, you would have to also add the condition && Key != '.'.

void __fastcall TRentalDialog::StayKeyPress(TObject *Sender, char &Key)
{
   if ((Key <'0' || Key >'9') && Key != 8 && Key != '\b') 
      Key = 0;
}
//---------------------------------------------------------------------------