• C++ Builder XE关于vector超速载入到listView表中


    先要在Unit.h中预载入

    #include        //用于虚拟listview

    //---------------------------------------------------------------------------
    //用于存储一条数据的结构体

    struct ListViewData         //用于存储一条数据的结构体
    {
            AnsiString  Caption;
            AnsiString SubItems1;
            AnsiString SubItems2;
            AnsiString DDnum;
            int stateindex;
    };

    private:    // User declarations
    void __fastcall WndProc(Winapi::Messages::TMessage &Message);
    std::vector m_lvDataVector;         //用于存储所以数据的向量

    AnsiString Dir="";

         //Dir里保存着所选的文件夹绝对路径
        //为空退出
        //Dir= RzSelectFolderDialog1->SelectedPathName;
      //判定是否批量处理
    //  if(Form2->DByn)
    //  {
    //    Dir=Form2->RzButtonEdit5->EditText;
    //    Form2->DByn=false;
    //  }
    //  else
    //  {
      if(PLyn)
      {
         Dir=Form1->PLstr;
      }
      else
      {
        if(RzSelectFolderDialog1->Execute())
        {
         Dir =RzSelectFolderDialog1->Directory;
         //Form5->RzMaskEdit1->EditText=RightStr(Dir,3);
         //RzMaskEdit1->EditText= RightStr(Dir,3);
        }
        else
          return;
      }
    //  }

      //-----------------------
       if (Dir.Length()==0)
          return;

        //++++++++++++++++++++++++++++++++++++++++++++
         //计算时间
         clock_t start,end,dtStart;
         start=clock();
         //
         RzProgressBar1->Percent=0;
         //++++++++++++++++++++++++++++++++++++++++++++
        int i,num,Lnum;
        Lnum=ListView1->Items->Count;

        TListItem *pItem=0;
       TSearchRec   sr;
       //int iAttributes=0x0000003F;

       if   (FindFirst(Dir+"\\*.txt",faAnyFile,sr)   ==   0)
          {

                ListView1->OwnerData=true;
                //const int iListViewCount=count;
                         //必须指定,以使ListView知道其虚拟数据量
                //保存数据
                TStringList *Xtmp=new TStringList;
                //Xtmp->Delimiter=' ';
                Xtmp->Clear();
    //      ListView1->Items->BeginUpdate();
              do
              {
                 int LScount=m_lvDataVector.size();//ListView1->Items->Count ;
    //                 pItem=ListView1->Items->Add();
    //                 pItem->Caption=Lnum+1;
    //                 pItem->SubItems->Add(sr.Name);
    //                 pItem->SubItems->Add("***"); //注数
    //                 pItem->SubItems->Add(Dir+"\\"+sr.Name); //注数
    //                 pItem->SubItems->Add("*");
    //                 pItem->SubItems->Add("*");
    //                 pItem->SubItems->Add("*");
    //                 pItem->SubItems->Add("*");
    //                 //
    //                 ListView1->Items->Item[Lnum]->ImageIndex=5;
    //                 ListView1->Items->Item[Lnum]->Checked=true;
                      //sss->Add(sr.Name);
                //载入文本数据
                Xtmp->LoadFromFile(Dir+"\\"+sr.Name );
                ListView1->Items->Count=Xtmp->Count+LScount;
                //
                for(int Di =0;Di Count;Di++)
                {
                    ListViewData *plvData=new ListViewData;
                    plvData->Caption=String(LScount+Di+1);           //   AnsiString().sprintf("%03d",LScount+Di+1);
                    plvData->SubItems1=Xtmp->Strings[Di] ;              //OpenDialog1->Files->Strings[i];
                    plvData->SubItems2="";               //ExtractFileName(OpenDialog1->Files->Strings[i]);
                    plvData->DDnum="***";
                    //plvData->SubItems2=IntToStr((xsx->Strings[i].Length()+1)/4);
                    plvData->stateindex=1;
                    //plvData-> SubItems3   = IntToStr((xsx->Strings[i].Length()+1)/4);
                    m_lvDataVector.push_back(plvData);           //向vector中添加一项
                    //delete plvData;
                }

                      Lnum+=1;
                      //++++++++++++++++++++++++++++++++++++++++++++
                       if(Lnum<100)
                       RzProgressBar1->Percent=Lnum;
                       Application->ProcessMessages();
                      //++++++++++++++++++++++++++++++++++++++++++++
              } while(FindNext(sr) == 0);
              FindClose(sr);
    //          ListView1->Items->EndUpdate();
          }
    //   Lnum=ListView1->Items->Count;
       //PageControl1->ActivePageIndex=0;
         // +++++++++++++++++++++++++++++++++++++++++++++++
         //操作完成计时
         end=clock();
         dtStart=end-start;
         dtStart=end-start;
         float dSec=float(dtStart)/1000;
         RzProgressBar1->Percent=100;
         RzStatusPane1->Caption="预导入大底:"+String(m_lvDataVector.size())+" 个";
         ListView1->Columns->Items[0]->Caption="id ["+String(m_lvDataVector.size())+"]";
         RzStatusPane2->Caption =
            "耗时:"+FloatToStrF(dSec,ffFixed,4,3)+" 秒 ";

  • 相关阅读:
    线性回归(机器学习)
    有限公司注册资金多少有什么区别
    算法day29|491,46,47
    RabbitMQ之Direct(直连)Exchange解读
    1、深入了解MySQL中内部组件架构(连接器,查询缓存,分析器,优化器,执行器等)
    [python] 利用 Pydoc 快速生成整个 Python 项目的文档
    【网络编程】进程间的通信
    牛客 NC24755 [USACO 2010 Dec S]Apple Delivery
    数仓建设(三)
    炫龙T6-E7A2电脑如何U盘重装系统解决系统故障教学
  • 原文地址:https://blog.csdn.net/lzksword/article/details/128000341