DBMNG数据库管理与应用

书籍是全世界的营养品。生活里没有书籍,就好像没有阳光;智慧里没有书籍,就好像鸟儿没有翅膀。
当前位置:首页 > 经验分享 > Delphi

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;

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号