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

先要在Unit.h中预载入

#include <vector>       //用于虚拟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 <ListViewData *> 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 <Xtmp->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)+" 秒 ";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lzksword

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值