![]() |
![]() ![]() ![]() |
acHTTP, acAutoUpgrader and acSendMail components.
|
type
|
TauHTTPProgressEvent = procedure(Sender: TObject;
|
const ContentType: String; FileSize, BytesRead, ElapsedTime,
|
EstimatedTimeLeft: Integer; PercentsDone: Byte;
|
TransferRate: Single; Stream: TStream) of object;
|
|
property OnProgress: TacHTTPProgressEvent;
|
The OnProgress event occurs every time when component has successfully downloaded part of data received in response to HTTP query.
|
|
Write OnProgress event handler to show the download progress (PercentsDone parameter indicate the progress in percents) or handle part of data which already received (Stream parameter). Also, the acHTTP component automatically calculates elapsed and estimated time before finishing download and speed of data transfer.
|
|
The acHTTP passes to the OnProgress event handler following parameters:
|
Parameter | Meaning
|
ContentType | the MIME-type of received data. For example if you downloaded usual text-file, the ContentType will be "text/plan". For HTML page ContentType will "text/html", for executable file "application/binary" and "image/jpeg" for JPEG, JPG and JPE files.
|
For more information about Internet media types, please read RFC 2045, 2046, 2047, 2048, and 2077. Check out also the Internet media type registry at ftp://ftp.iana.org/in-notes/iana/assignments/media-types;
|
DataSize | total size of data 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" content types);
|
BytesRead | size of already received data, in bytes;
|
ElapsedTime | time elapsed from beginning of download (in seconds);
|
EstimatedTimeLeft | estimated time left before finishing of download (Formula:
|
X := FileSize / BytesRead * ElapsedTime - ElapsedTime);
|
PercentsDone | progress in percents (0%..100%);
|
TransferRate | speed of data transfer (in Kb/s);
|
Stream | stream which contains already downloaded data. (Check out description of TStream, TMemoryStream and TFileStream classes for more info).
|
|
![]() |
procedure TForm1.HTTP1Progress(Sender: TObject; ContentType: String; FileSize, BytesRead, ElapsedTime, EstimatedTimeLeft: Integer; PercentsDone: Byte; TransferRate: Single; Stream: TStream);
|
begin
|
// progress bar position
|
CurrentFileProgressBar.Position := PercentsDone;
|
|
// file size
|
FileSizeLabel.Caption :=
|
Format('File size: %.1f Kb', [FileSize / 1024]);
|
|
// downloaded (in Kb)
|
DownloadedLabel.Caption :=
|
Format('Downloaded: %.1f Kb:', [BytesRead / 1024]);
|
|
// transfer rate
|
TransRateLabel.Caption :=
|
Format('Transfer rate: %.1f Kb/s', [TransferRate]);
|
|
// estimated time left
|
EstTimeLeftLabel.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;
|
void __fastcall TForm1::acHTTP1Progress(TObject *Sender,
|
AnsiString ContentType, int FileSize, int BytesRead,
|
int ElapsedTime, int EstimatedTimeLeft,
|
BYTE PercentsDone, float TransferRate, TStream *Stream)
|
{
|
// progress bar position
|
ProgressCurrentFile->Position = PercentsDone;
|
|
// file size
|
FileSizeLabel->Caption =
|
Format("File size: %.1f Kb:",
|
ARRAYOFCONST(((float)FileSize / 1024)));
|
|
// downloaded (in Kb)
|
DownloadedLabel->Caption =
|
Format("Downloaded: %.1f Kb:",
|
ARRAYOFCONST(((float)BytesRead / 1024)));
|
|
// transfer rate
|
TransRateLabel->Caption =
|
Format("Transfer rate: %.1f Kb/s",
|
ARRAYOFCONST(((float)TransferRate)));
|
|
// estimated time left
|
EstTimeLeftLabel->Caption =
|
Format("Estimated time left: %d:%.2d:%.2d",
|
ARRAYOFCONST((EstimatedTimeLeft / 60 / 60, // hours
|
EstimatedTimeLeft / 60 % 60, // minutes
|
EstimatedTimeLeft % 60 % 60))); // seconds
|
}
|
OnDone event.
|