zoukankan      html  css  js  c++  java
  • Delphi带进度条复制文件

    function FileCopy(SourceFile,TargetFile : string;ProgressBar :TRzProgressStatus ) : boolean;

    //function FileCopy(SourceFile,TargetFile : string;ProgressBar :TProgressBar ) : boolean;
    var
      getStream,setStream: TFileStream;
      num, n: Integer;
      buf: PByte;
      BufSize,block: Integer;
    begin
      result := false;
      if not FileExists(SourceFile) then
      begin
        //ShowMessage('源文件不存在!');
        Exit;
      end;

      getStream := TFileStream.Create(SourceFile, fmOpenRead or fmShareExclusive);
      setStream := TFileStream.Create(TargetFile, fmCreate);

      num := getStream.Size;
      setStream.Size := num;
      getStream.Position := 0;
      setStream.Position := 0;

      BufSize := num;
      block := BufSize div 100;
      GetMem(buf, BufSize);

     // ProgressBar.Max := 100;
      ProgressBar.Percent := 0;
      //ProgressBar.min := 0;
      //ProgressBar.Position := 0;

      while num <> 0 do
      begin
        Application.ProcessMessages;
        n := block;
        if n > num then n := num;
        getStream.ReadBuffer(buf^, n);
        setStream.WriteBuffer(buf^, n);
        ProgressBar.Percent := Trunc((1 - num / BufSize)*100);
        //ProgressBar.Position := Trunc((1 - num / BufSize)*100);
        Dec(num, n);
      end;
      ProgressBar.Percent := 0;
      //ProgressBar.Position := 0;
      FreeMem(buf, BufSize);
      getStream.Free;
      setStream.Free;
      result := true;
    end;

  • 相关阅读:
    iOS图片拉伸技巧
    Swift和OC混合使用
    【转】动态计算UITableViewCell高度详解
    AutoLayout~Label
    【转】初探 iOS8 中的 Size Class
    Objective-C runtime~
    [转]Objective-C中的类和对象(instance)
    Masonry~
    [转] ios学习--openURL的使用方法
    Autolayout~代码实现
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/2178733.html
Copyright © 2011-2022 走看看