براي استفاده از اين Procedureها بايد يك Progressbar و يك Label روي فرم خود قرار دهيد.

 

 procedure TForm1.CopyFileWithProgressBar1
 (Source, Destination: string);
 var
   
FromF, ToF: file of byte;
   Buffer: array[0..4096] of char;
   NumRead: integer;
   FileLength: longint;
 begin
   
AssignFile(FromF, Source);
   reset(FromF);
   AssignFile(ToF, Destination);
   rewrite(ToF);
   FileLength := FileSize(FromF);
   with Progressbar1 
do
   begin
     
Min := 0;
     Max := FileLength;
     while FileLength > 0 
do
     begin
       
BlockRead(FromF, Buffer[0], SizeOf(Buffer), NumRead);
       FileLength := FileLength - NumRead;
       BlockWrite(ToF, Buffer[0], NumRead);
       Position := Position + NumRead;
     end;
     CloseFile(FromF);
     CloseFile(ToF);
   end;
 end;


 procedure TForm1.Button1Click(Sender: TObject);
 begin
   
CopyFileWithProgressBar1('c:\Windows\Welcome.exe',
   'c:\temp\Welcome.exe');
 end;

{***************************************}
// To show the estimated time to copy a file:

  procedure TForm1.CopyFileWithProgressBar1
  (Source, Destination: string);
 var
   
FromF, ToF: file of byte;
   Buffer: array[0..4096] of char;
   NumRead: integer;
   FileLength: longint;
   t1, t2: DWORD;
   maxi: integer;
 begin
   
AssignFile(FromF, Source);
   reset(FromF);
   AssignFile(ToF, Destination);
   rewrite(ToF);
   FileLength := FileSize(FromF);
   with Progressbar1 
do
   begin
     
Min  := 0;
     Max  := FileLength;
     t1   := TimeGetTime;
     maxi := Max div 4096;
     while FileLength > 0 
do
     begin
       
BlockRead(FromF, Buffer[0], SizeOf(Buffer), NumRead);
       FileLength := FileLength - NumRead;
       BlockWrite(ToF, Buffer[0], NumRead);
       t2  := TimeGetTime;
       Min := Min + 1;
       
// Show the time in Label1
       
label1.Caption := FormatFloat
       ('0.00', ((t2 - t1) / min * maxi - t2 + t1) / 100);
       Application.ProcessMessages;
       Position := Position + NumRead;
     end;
     CloseFile(FromF);
     CloseFile(ToF);
   end;
 end;