mythread.cpp

来自「zip算法的源码」· C++ 代码 · 共 73 行

CPP
73
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MyThread.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------

//   Important: Methods and properties of objects in VCL can only be
//   used in a method called using Synchronize, for example:
//
//      Synchronize(UpdateCaption);
//
//   where UpdateCaption could look like:
//
//      void __fastcall Unit1::UpdateCaption()
//      {
//        Form1->Caption = "Updated in a thread";
//      }
//---------------------------------------------------------------------------

__fastcall TMyThread::TMyThread(AnsiString PathT, AnsiString FileT,
                                TLabel* LblOk, TLabel* LblErr, bool CreateSuspended)
                                : TThread(CreateSuspended)
{
  Priority = tpNormal;
  FreeOnTerminate = true;
  Path = PathT;
  File = FileT;
  LabelOk = LblOk;
  LabelErr = LblErr;
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
  Zipp = new TZipBuilder(NULL);
  Zipp->Load_Zip_Dll();
  Zipp->ZipFileName = File;
  Ok = Err = 0;
  Synchronize(UpdateLabels);
  TSearchRec SRec;
  if(FindFirst(Path + "*.*", faAnyFile, SRec) == 0)
  {
    do
    {
      if(SRec.Attr != faDirectory && SRec.Name != "." && SRec.Name != "..")
      {
        Zipp->FSpecArgs->Add(Path + SRec.Name);
        try
        {
          Zipp->Add();
          if(!Zipp->ErrCode) ++Ok;
          else ++Err;
        }
        catch(...)
        {
          ++Err;
        }
        Synchronize(UpdateLabels);
      }
     } while (FindNext(SRec) == 0);
    FindClose(SRec);
  }
  Zipp->Unload_Zip_Dll();
  delete Zipp;
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::UpdateLabels(void)
{
  LabelOk->Caption = IntToStr(Ok);
  LabelErr->Caption = IntToStr(Err);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?