I'm having an issue where I am trying to keep a database up to date with a form, i.e. when a user clicks an item on a check list, the database is updated. The problem is that when a user checks and unchecks a box too fast, the form and the database do get out of sync, and an exception is thrown. Can someone tell me a better way to do this? Even with the sleep and the disable/enable things I've added, it is still quite easy to click the form faster than the database update can take place.
Thanks for any tips. The offending function is included below:
void __fastcall TResourcePoolingForm::ResourcesCheckClickCheck(
TObject *Sender)
{
//first make sure there's a pool selected
int pIndex = PoolsList->ItemIndex;
if (pIndex < 0) return;
//also make sure there is a resource selected
int rIndex = ResourcesCheck->ItemIndex;
if (rIndex < 0) return;
ResourcesCheck->Enabled = false;
if (ResourcesCheck->Checked[rIndex])
{
//add a this to the pool
DirectoryDBModule->addResourceToPool(mPools[pIndex]->getIdString(),
mResources[rIndex]->getIdString());
}
else
{
//remove this from the pool
DirectoryDBModule->removeResourceFromPool(mPools[pIndex]->getIdString(),
mResources[rIndex]->getIdString());
}
reload();
Sleep(200);
ResourcesCheck->Enabled = true;
}
Thanks for any tips. The offending function is included below:
void __fastcall TResourcePoolingForm::ResourcesCheckClickCheck(
TObject *Sender)
{
//first make sure there's a pool selected
int pIndex = PoolsList->ItemIndex;
if (pIndex < 0) return;
//also make sure there is a resource selected
int rIndex = ResourcesCheck->ItemIndex;
if (rIndex < 0) return;
ResourcesCheck->Enabled = false;
if (ResourcesCheck->Checked[rIndex])
{
//add a this to the pool
DirectoryDBModule->addResourceToPool(mPools[pIndex]->getIdString(),
mResources[rIndex]->getIdString());
}
else
{
//remove this from the pool
DirectoryDBModule->removeResourceFromPool(mPools[pIndex]->getIdString(),
mResources[rIndex]->getIdString());
}
reload();
Sleep(200);
ResourcesCheck->Enabled = true;
}