user3424509
user3424509

Reputation: 55

Getting the file upload speed with Delphi

I have coded some tool using Delphi 2010 and clever internet suite for logging into a website and uploading a file.

Everything works fine, and now I would like to add the upload speed rate, but I don't know how to do it.

I have spent the whole day googling around, but it did not bring any positive results.

I was trying in this part:

procedure TForm2.clHttp1SendProgress(Sender: TObject; ABytesProceed,
  ATotalBytes: Int64);
begin

end;

Could someone please explain me how to do that or just give some tip?

Upvotes: 0

Views: 347

Answers (1)

Sir Rufo
Sir Rufo

Reputation: 19106

"Speed" is defined as an amount per timespan. To calculate you must know what amount and what timespan.

Just store the current amount and the current timestamp and next time you can calculate the speed

(current_amount - last_amount)/(current_timestamp - last_timestamp)
TForm2 = ...
...
private
  FBytesProceed : Int64;
  FTimeStamp : TDateTime;
  FSpeed : double;
end;

procedure TForm2.clHttp1SendProgress(Sender: TObject; ABytesProceed,
  ATotalBytes: Int64);
var
  LTimeStamp : TDateTime;
begin
  LTimeStamp := Now;
  if FBytesProceed < ABytesProceed then
  begin
    // calculating bytes per second
    FSpeed := ( ABytesProceed - FBytesProceed ) {bytes}
            / ( ( LTimeStamp - FTimeStamp ) {days}
              * 24 {hours}
              * 60 {minutes}
              * 60 {seconds} );
  end;
  FBytesProceed := ABytesProceed;
  FTimeStamp := LTimeStamp;
end;

Upvotes: 3

Related Questions