was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

40 Visitors Online


 
...die Dauer eines Datei-Downloads einschätzen?
Autor: Patrik Forsberg
Homepage: http://www.coldmind.com
[ Tip ausdrucken ]  

Tip Bewertung (11):  
     


{ Add this under your type declaration

type
  TDRec = record
H,M,S: Integer;
  end;

}
  
TDRec = record
  
H, M, S: Integer;
  end;
{*****}

const
  
Count = 6;
  BpsArray: array [0..Count] of Integer = (14400,
    28800,
    33600,
    56000,
    64000,
    128000,
    512000
    );

function CalculateDLTime(const Value, Units, Connection: Integer): TDRec;
var
  
i, size_bits, filedltimesec, hourmod, HH, MM, SS: Integer;

  Rec: TDRec;

  function pow(a, b: Integer): Integer;
    function sl(nr, times: Integer): Integer;
    var
      
i: Integer;
    begin
      
Result := nr * nr;
      for i := 0 to times do Result := Result + nr * nr;
    end;
  begin
    if 
a > b then Result := sl(a, b)
    else 
      
Result := sl(b, a);
  end;
begin
  case 
Units of
    
1: size_bits := (8 div 1) * Value;                 // bytes
    
2: size_bits := (8 div 1) * ((pow(2,10)) div 1) * Value;     // kilobytes
    
3: size_bits := (8 div 1) * ((pow(2,20)) div 1) * Value;     // Megabytes
  
end;

  // Calculate
  
filedltimesec := Round(size_bits) div BpsArray[Connection];

  hourmod := filedltimesec mod (60 * 60);  // Modulus.
  
HH      := Floor(filedltimesec / (60 * 60));
  MM      := Floor(hourmod / 60);
  SS      := Floor(filedltimesec mod 60);  // Modulus.

  
if SS > 0 then Inc(SS);

  with Rec do
  begin
    
H := HH;
    M := MM;
    S := SS;
  end;

  Result := Rec;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
i: Integer;
  Rec: TDRec;
begin
  
ListView1.Items.Clear;

  for i := 0 to Count do
  begin
    
Rec := CalculateDLTime(StrToInt(Edit1.Text), ComboBox1.ItemIndex + 1,i);

    with ListView1.Items.Add do
    begin
      
Caption := NameArray[i];
      SubItems.Add(IntToStr(Rec.H));
      SubItems.Add(IntToStr(Rec.M));
      SubItems.Add(IntToStr(Rec.S));
    end;
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners