delphi 拷贝文件时有进度显示

procedure TForm1.mycopyfile(sourcef,targetf:string);
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
n:integer;
begin
   AssignFile(FromF, sourcef);
   Reset(FromF, 1); { Record size = 1 }
   AssignFile(ToF,targetf); { Open output file }
   Rewrite(ToF, 1); { Record size = 1 }
   n:=0;
   repeat
        BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
        form1.label1.caption:=IntToStr(sizeof(buf)*n*100 div FileSize(FromF))+'100%';
        application.ProcessMessages;
        //显示进度
        BlockWrite(ToF, Buf, NumRead, NumWritten);
        inc(n);
    until (NumRead = 0) or (NumWritten <> NumRead);
    form1.Label1.Caption:='100%';
    CloseFile(FromF);
    CloseFile(ToF);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
mycopyfile('e:/components/tv2k-w2k.zip','c:/a.zip');
end;

posted @ 2019-03-11 17:27  YJCCN  阅读(491)  评论(0编辑  收藏  举报