mercredi 12 août 2015

TIdThrottler, TEdit, and TCheckBox Validations

This is related to the Indy's TIdThrottler implementation.

My purpose is that the users will never be able to check a TCheckBox when the number is entered into a TEdit less than 7 digits. Also, this TCheckBox can never be checked when the TEdit is being empty.

A problem of my codes is sometimes TCheckBox can still be checked although TEdit is being empty.

Moreover, my another target is that the start button can never be executed or will always display an error message if the start button is clicked when the TCheckBox is checked while the TEdit is being empty.

The problem is what codes should I put in the start button ?.

I am using the following code:

//--------------------------------------------------------------------------------
void __fastcall TForm::MyTEditBoxKeyPress(TObject *Sender, System::WideChar &Key)
{
  if( Key == VK_BACK ) return;
    if((Key < '1') || (Key > '9'))
     {
      MessageDlg("Please enter number only.",mtInformation, TMsgDlgButtons()<< mbOK, 0);
      Key = 0;
  }
}
//--------------------------------------------------------------------------------
void __fastcall TForm::MyTEditBoxExit(TObject *Sender)
{
   if (MyTEditBox->Text.Length() < 7) {
   MessageDlg("Please enter at least 7 digit.",mtInformation, TMsgDlgButtons()<< mbOK, 0);
   }
}
//--------------------------------------------------------------------------------
void __fastcall TForm::MyCheckBoxClick(TObject *Sender)
{
   if (MyCheckBox->Tag == 0 ) {
    MyCheckBox->Tag = 1;
    if (MyTEditBox->Text.Length() >= 7)
    MyCheckBox->Checked = true;
    IdThrottler->BitsPerSec = StrToInt64(MyTEditBox->Text);
   }
   else {
     MyCheckBox->Tag = 0;
      if (MessageDlg("Please enter at least 7 digit.",mtInformation, TMsgDlgButtons()<< mbOK, 0) == mrYes)
     MyCheckBox->Checked = false;
   }
}




Aucun commentaire:

Enregistrer un commentaire