2012年1月6日 星期五

limited TEdit key in 0~9 and value in BCB

//limited 0~9 and value < 65535 in BCB
void __fastcall TMain::edtPortKeyPress(TObject *Sender, char &Key)
{
     if (((Key >= '0') && (Key <= '9')) || (Key == '\b'))
     {
        if ((Key >= '0') && (Key <= '9'))
        {
            if (StrToInt(edtPort->Text+Key) > 65535)
                Key = 0;
        }
     }
     else
     {
        Key = 0;
     }
}