Ver Mensaje Individual
  #2  
Antiguo 11-04-2008
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Reputación: 28
jachguate Va por buen camino
No me acuses de no preferir la POO, pero para algo como esto, no hace falta un componente...

Alguna vez hice algo como esto, que ahora se me ocurre:

Código Delphi [-]
function BytesToStr(const Bytes: Int64): string;
{
by: jachguate
    http://jachguate.wordpress.com
}
Const
  KB = 1024;
  MB = 1024 * KB;
  GB = 1024 * MB;
  TB = 1024.0 * GB;
var
  Valor: Double;
  Unidad: string;
  Decimales: Byte;

begin
  Decimales := 2;
  if Bytes < KB then
  begin
    Valor := Bytes;
    Unidad := 'Bytes';
    Decimales := 0;
  end
  else if Bytes < MB then
  begin
    Valor := Bytes / KB;
    Unidad := 'KB';
  end
  else if Bytes < GB then
  begin
    Valor := Bytes / MB;
    Unidad := 'MB';
  end
  else if Bytes < TB then
  begin
    Valor := Bytes / GB;
    Unidad := 'GB';
  end
  else
  begin
    Valor := Bytes / TB;
    Unidad := 'TB';
  end;
  Result := Format('%.*f %s', [Decimales, Valor, Unidad]);
end;

Hasta luego.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate

Última edición por jachguate fecha: 11-04-2008 a las 08:53:24.
Responder Con Cita