Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : idhttp calculation problem , need help!
| Subject: | idhttp calculation problem , need help! |
| Posted by: | "inqontrol" (te..@odium.to) |
| Date: | Sat, 8 Mar 2008 18:32:14 |
Hello,
I really love the indy components. But I have a problem. Since I'm coding a
lot of applications for up- and downloading files I experienced that on
nearly all client computers my tools works correct. But on some client
computers the speed, progress and time-left calculations go crazy. I use
IDHttp for up- and downloading files to webservers with a special api (such
as rapidshare.com). I use the latest indy version with Delphi 2007.
Here is an example:
var
pos, max, prozent, newtime, etasec: integer;
begin
newtime := GetTickCount; //latest time
pos := idhttp.fWorkPos; //downloaded bytes
max := idhttp.fMaxCount; //maximum of bytes
prozent := round(pos * 100 / max); //percent
if newtime > fLastTime then
begin
speed := (pos - fOldBytes) / (newtime - fLastTime); //calculate Bytes/s
speed := (speed + fOldSpeed) / 2; //average for avoiding fluctuations
etasec:= round(((max - pos) / 1024) / speed); //ETA in sec.
end
else
speed := 0;
.. Time Left: Format('%.2d:%.2d:%.2d', [etasecdiv 3600, etasec div 60
mod 60, etasec mod 60]);
.. Format('%.2f', [speed]) + 'KB/s';
fOldBytes := pos;
fLastTime := newtime;
fOldSpeed := speed;
end;
On some computers the speed, progress and time increase up to an impossible
value but I cannot figure out why this happens on only some computers, on
others it's working wonderful.
Please help me!
Thanks.
inqontrol