autoupgrader OnProgress event
Return to Introduction  Previous page  Next page
Applies to
auAutoUpgrader and auHTTP components.  

Declaration
type  
  TauAUProgressEvent = procedure(Sender: TObject;  
FileURL: String; FileSize, BytesRead, ElapsedTime,  
EstimatedTimeLeft: Integer;  
PercentsDone, TotalPercentsDone: Byte;  
TransferRate: Single) of object;  
 
property OnProgress: TauAUProgressEvent;  

Description
The OnProgress event occurs every time when component has successfully downloaded part of some file which should be updated.  
 
Write the OnProgress event handler to show the download progress and implement your own, custom progess box instead of standard Application update wizard (then set Enabled property of Wizard structure to False), or use it as an addition to standard wizard.  
 
There are following parameters which passes to the event handler:  
ParameterMeaning  
FileURLlocation of the file which currently downloading. (This file is one of that that listed in remote Info-file, from which we have gotten an upgrade information.);  
FileSizetotal size of file which we currently downloading, in bytes (if possible to determinate).  
Note: usually server does not provide information about content-length for non-binary data (i.e: for "text/html" or "text/plain" MIME-types);  
BytesReadsize of already received data, in bytes;  
ElapsedTimetime elapsed from beginning of download (in seconds);  
EstimatedTimeLeftestimated time left before finishing of download (Formula:  
X := FileSize / BytesRead * ElapsedTime - ElapsedTime);  
PercentsDoneprogress for current file in percents (0%..100%);  
TotalPercentsDoneprogress for whole download queue in percents (0%..100%);  
TransferRatespeed of data transfer (in Kb/s).  
 
tip The OnProgress event triggered after downloading each block of data with size specified in TransferBufferSize property.  

Example
Delphi:
procedure TForm1.auAutoUpgrader1Progress(Sender: TObject;  
  FileURL: string; FileSize, BytesRead, ElapsedTime,  
  EstimatedTimeLeft: Integer; PercentsDone,  
  TotalPercentsDone: Byte; TransferRate: Single);  
begin  
  // two progress bars  
  ProgressCurrentFile.Position := PercentsDone;  
  ProgressAllFiles.Position := TotalPercentsDone;  
 
  // file size label (in Kb)  
  FileSizeLabel.Caption :=   
       Format('File size: %.1f Kb', [FileSize / 1024]);  
 
  // downloaded size label (in Kb)  
  DownloadedLabel.Caption :=   
       Format('Downloaded: %.1f Kb', [BytesRead / 1024]);  
 
  // transfer rate label (in Kb per second)  
  TransRateLabel.Caption :=   
       Format('Transfer rate: %.1f Kb/s', [TransferRate]);  
 
  // estimated time left label  
  EstTimeLabel.Caption :=   
       Format('Estimated time left: %d:%.2d:%.2d',  
        [EstimatedTimeLeft div 60 div 60,   // hours  
         EstimatedTimeLeft div 60 mod 60,   // minutes  
         EstimatedTimeLeft mod 60 mod 60]); // seconds  
end;  



C++ Builder:

void __fastcall TForm1::auAutoUpgrader1Progress(TObject *Sender,  
      AnsiString FileURL, int FileSize, int BytesRead,  
      int ElapsedTime, int EstimatedTimeLeft,  
      BYTE PercentsDone, BYTE TotalPercentsDone,  
      float TransferRate)  
{  
  // two progress bars  
  ProgressCurrentFile->Position = PercentsDone;  
  ProgressAllFiles->Position = TotalPercentsDone;  
 
  // file size label (in Kb)  
  FileSizeLabel->Caption = Format("File size: %.1f Kb", ARRAYOFCONST(((float)FileSize / 1024)));  
 
  // downloaded size label (in Kb)  
  DownloadedLabel->Caption = Format("Downloaded: %.1f Kb", ARRAYOFCONST(((float)BytesRead / 1024)));  
 
  // transfer rate label (in Kb per second)  
  TransRateLabel->Caption = Format("Transfer rate: %.1f Kb/s", ARRAYOFCONST(((float)TransferRate)));  
 
  // estimated time left label  
  EstTimeLabel->Caption =   
       Format("Estimated time left: %d:%.2d:%.2d",  
       ARRAYOFCONST((EstimatedTimeLeft / 60 / 60,   // hours  
                     EstimatedTimeLeft / 60 % 60,   // minutes  
                     EstimatedTimeLeft % 60 % 60)));// seconds  
}  

See also
Wizard structure; Info-file example;  
OnBeginUpgrade, OnEndUpgrade and OnFileDone events.  
File not found.