GotoBookmark tooo slow?

GotoBookmark tooo slow?

孤独患者 发布于 2021-11-27 字数 4617 浏览 798 回复 2 原文

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

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

々眼睛长脚气 2022-06-07 2 楼

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.

难得心□动 2022-06-07 1 楼

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.