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;

相关阅读 >>

Delphi xe android platform uses-permission[1] 权限列表

Delphi webbroker 上传文件

Delphi 7 中dbgrid的排序

Delphi系统默认语言与系统支持的语言列表

Delphi 让窗体自适应屏幕显示

Delphi memo 循环往上往下滚动

Delphi来实现全屏截图

Delphi application.messagebox 详解

Delphi paramstr 获取外部参数

Delphi 字符串加密解密(不支持中文)

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...