What I am trying to accomplish is simple; however, whenever I write this simple switch function, I can't help but ask whether or not there is a better way to do this:
void __fastcall TForm1::Edit5KeyPress(TObject *Sender, char &Key)
{
switch (Key) {
case '1' : ;
case '2' : ;
case '3' : ;
case '4' : ;
case '5' : ;
case '6' : ;
case '7' : ;
case '8' : ;
case '9' : ;
case '0' : ;
case '.' : ;
case char(13) : ;
case char(8) : ;
default : Key = char(13);
break;
}
}
// Key is a direct variable of the typed key.
Basically, as you can see, this only allows for numeric keys, the decimal key, [enter], and [backspace] to be used. Other keys register as the [enter] key, which does nothing in an edit box.
In Delphi, this is what one would do:
case Key of
'0'..'9' : ;
chr(13) ......... etc.
That saved a bunch of typing. Sure it doesn't seem like much for something like this, but what if I wanted to do something similar where about 50 different things had to be disabled and 50 enabled? This would get tedious...
What can I do?