我现在执行copyFile,
请问TProgressbar怎样成比例增加直至复制完成,
并显示0%到复制完后显示100%
象windows复制文件一样

解决方案 »

  1.   

    //一下代码是拷贝一个目录的文件到另外一个目录
    //拷贝过程会自动调用windows拷贝文件的进度窗口
    //仅供参考uses shellapi, INIFiles;var
      OpStruc: TSHFileOpStruct;
      frombuf, tobuf: Array [0..255] of Char;
      iniFile: TIniFile;
      sSource, sDestination: String;
    Begin
      iniFile := TIniFile.Create('.\Settings.ini');
      try
        Application.ProcessMessages;    sSource := iniFile.ReadString('Paths', 'Source', '');
        sDestination := iniFile.ReadString('Paths', 'Destination', '');
        if (not DirectoryExists(sSource))
          or (not DirectoryExists(sDestination)) then
          Abort;    if (iniFile.ReadInteger('Paths', 'CreateNewDir', 1) = 1) then
        begin
          sDestination := sDestination + '\' +
            StringReplace(FormatDateTime('yyyy-mm-dd, hh:mm', Now), ':', ':', [rfReplaceAll]);
          if (not CreateDir(sDestination)) then
            Abort;
        end;    FillChar(frombuf, Sizeof(frombuf), 0);
        FillChar(tobuf, Sizeof(tobuf), 0);
        StrPCopy(frombuf, sSource + '\*.*');
        StrPCopy(tobuf, sDestination);
        With OpStruc DO Begin
          Wnd := Handle;
          wFunc := FO_COPY;
          pFrom := @frombuf;
          pTo := @tobuf;
          fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
          fAnyOperationsAborted := False;
          hNameMappings := Nil;
          lpszProgressTitle := Nil;
        end;
        ShFileOperation(OpStruc);
      finally
        iniFile.Free;
        FCanClose := True;
        Self.Close;
      end;
    end;
      

  2.   

    TProgressbar没?%进度
    Sample 版面 上 TGauge有,看你需要...
      

  3.   

    提供两个函数供参考:
    CopyFileEx(),CopyProgressRoutine()用 CopyFile 无法得知文件复制的进度。