views:

335

answers:

2

Hi,

I'm fixing a C++ Builder 5 application and I have this code:

void __fastcall TFPrincipal::DBGModuleStartDrag(TObject *Sender,
        TDragObject *&DragObject)
{
  m_pParentNodesDragDrop = NULL;
  DragObject = NULL;
  bool bAbort = false;
  m_ListaModulosDragDrop->Clear();
  m_ListaContenedoresDragDrop->Clear();
  CInfoNode *pInfoNode = NULL;
  CInfoModule *pInfoMod = NULL ;
  long l_IdContainerParent = 0;
  TDataSet * DataSet = NULL;

  m_pLastDragNode = NULL;
  m_bLastAccept = false;

  try
  {
        IProductsPtr ProductsPtr =
                m_pgServerConnection->Create<IProducts>( CLSID_CProducts );
        if(DBGModules)
        {
            if ( DBGModules->DataSource )
            {
              if ( DBGModules->DataSource->DataSet )
                {
                  DataSet = DBGModules->DataSource->DataSet;
                  DataSet->DisableControls();
                }
                else return;
            }
            else return;
        }
        else return;
      for (int i = 0; i < DBGModules->SelectedCount; i++)
      {
          DataSet->GotoBookmark(DBGModules->SelectedRows[i].c_str());


          pInfoMod = new CInfoModule( DataSet->FieldByName("IP")->AsString,
                  (long)DataSet->FieldByName("IdComputer")->AsInteger,
                  (Products)DataSet->FieldByName("IdProduct")->AsInteger,
                  DataSet->FieldByName("Host")->AsString,
                  DataSet->FieldByName("Instance")->AsString,
                  DataSet->FieldByName("Version")->AsString,
                  DataSet->FieldByName("AditionalInfo")->AsString,
                  (Antivirus)DataSet->FieldByName("IdAntivirus")->AsInteger,
                  DataSet->FieldByName("NumNotPadmin3AV")->AsInteger,
                  DataSet->FieldByName("NumPadmin3AV")->AsInteger,
                  false,
                  (long)DataSet->FieldByName("IdUnit")->AsInteger,
                  (long)DataSet->FieldByName("IdUnitForInstall")->AsInteger);
          DataSet->FreeBookmark(DataSet->GetBookmark());

          pInfoNode = new CInfoNode();
            pInfoNode->m_pInfoModule = pInfoMod;
      //  Platree::TPlaTreeNode *pNodoSeleccionado = pInfoNode;


      //  if (pNodoSeleccionado)
        {
        // guardamos el padre de uno de los nodos seleccionados para
        // el drag & drop para que usarlo luego para que aparezca desplegada
        // la rama de origen del nodo movido y la rama de destino tras
        // el refresco (parametro del ReloadTree)
        //  if ( ! m_pParentNodesDragDrop )
        //    m_pParentNodesDragDrop = pNodoSeleccionado->Parent;

          //CInfoNode *pInfoNodoSeleccionado;
          //pInfoNodoSeleccionado = (CInfoNode *)pNodoSeleccionado->Data;


          if (pInfoNode->IsModule())
          {
            long l_IdContainerParent = 0;
            m_ListaModulosDragDrop->AddObject(pInfoMod->m_asDisplayName,
                                              (TObject*)pInfoNode);
         /*   TESTHR(ProductsPtr->GetIDContainer(pInfoMod->m_lIdComputer,
                                        pInfoMod->m_pdIDProduct,
                                        WideString(pInfoMod->m_asInstance),
                                        &l_IdContainerParent));*/

           CInfoDragNode *pInfoDragNode = new CInfoDragNode();
           pInfoDragNode->m_asInstance = pInfoMod->m_asInstance;
           pInfoDragNode->m_lIdComputer = pInfoMod->m_lIdComputer;
           pInfoDragNode->m_lIdContainerParent = /*l_IdContainerParent*/0;
           pInfoDragNode->m_pdIDProduct = pInfoMod->m_pdIDProduct;

           m_ListaContenedoresDragDrop->Add(
                   reinterpret_cast<void*>(pInfoDragNode)
           );
          }
          else
            {
            bAbort = true;
            break;
          }
        }
    /*    delete pInfoNode;
        delete pInfoMod;*/
         DataSet->EnableControls();
      }
      if (bAbort)
      {
        // alguno de los items seleccionados no es un módulo
        m_ListaModulosDragDrop->Clear();
      }
    }
    catch (const nm_error::__com_error_ &e )
    {
       PutDebugMessage(COMError2str(e));
       m_ListaModulosDragDrop->Clear();
    }
}

And I have noticed the line DataSet->GotoBookmark(DBGModules->SelectedRows[i].c_str()); is being executed slow. Why can it be? The grid used is from DevExpress

+1  A: 

It may well be that your GotoBookmark is resulting in the query behind the DataSet being run again and again. It may be better to execute a more specific query depending on the selected row, rather than going to a bookmark in the results of a more generic query.

Jon Bright
+2  A: 

The GotoBookmark functionality and the use of Filters in Datasets in Delphi and C++ Builder is known to be a very serious performance bottleneck.

My suggestion would be to use a differnt mechanism for jumping to the required record. Perhaps simply using a query and an ID. If this is not possible make sure you have indexes on the fields being used as the bookmark key.

Toby Allen