0

我正在修复一个 C++ Builder 5 应用程序,并且我有以下代码:

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();
    }
}

我注意到 DataSet->GotoBookmark(DBGModules->SelectedRows[i].c_str()); 正在执行缓慢。为什么会这样?使用的网格来自 DevExpress

4

2 回答 2

2

众所周知,Delphi 和 C++ Builder 中的 GotoBookmark 功能和数据集中过滤器的使用是一个非常严重的性能瓶颈。

我的建议是使用不同的机制来跳转到所需的记录。也许只是使用查询和 ID。如果这不可能,请确保您在用作书签键的字段上有索引。

于 2009-05-20T11:34:54.377 回答
1

很可能是您的 GotoBookmark 导致 DataSet 后面的查询一次又一次地运行。根据所选行执行更具体的查询可能会更好,而不是转到更通用查询结果中的书签。

于 2009-05-16T22:22:33.290 回答