unitfunciones.pas

来自「远程控制软件」· PAS 代码 · 共 54 行

PAS
54
字号
unit UnitFunciones;

interface

uses Windows, SysUtils;

function ObtenerMejorUnidad(bytes: Int64):String;
function ObtenerMejorUnidadInv(Cadena: String):Int64;
function GetFileSize(const strFileName: String): LongInt;

implementation

function ObtenerMejorUnidad(bytes: Int64):String;
begin
  if bytes < 1024 then
    Result := IntToStr(bytes) + ' B'
  else if bytes < 1048576 then
    Result := FloatToStrF(bytes / 1024, ffFixed , 10, 1)+' Kb'
  else if bytes < 1073741824 then
    Result := FloatToStrF(bytes / 1048576, ffFixed , 10, 1)+' Mb'
  else if bytes > 1073741824 then
    Result := FloatToStrF(bytes / 1073741824, ffFixed , 10, 1)+' Gb';
end;

//Dada una cadena del tipo 44,7 Mb nos devuelve el numero de bytes equivalentes
function ObtenerMejorUnidadInv(Cadena: String):Int64;
var
  Unidad: String;
  Cantidad: Extended;
begin
  Result := -1;
  if Cadena = '' then exit;
  Unidad := Copy(Cadena, Pos(' ', cadena) + 1, Length(Cadena));
  Cantidad := StrToFloat(Copy(Cadena, 1, Pos(' ', cadena) - 1));
  if Unidad = 'B' then
    Result := Round(Cantidad);
  if Unidad = 'Kb' then
    Result := Round(Cantidad * 1024);
  if Unidad = 'Mb' then
    Result := Round(Cantidad * 1048576);
  if Unidad = 'Gb' then
    Result := Round(Cantidad * 1073741824);
end;

function GetFileSize(const strFileName: String): LongInt;
var WFD: TWin32FindData; hFile: THandle;
begin
  hFile := FindFirstFileA(PChar(strFileName), WFD);
  Result := WFD.nFileSizeLow;
  windows.FindClose(hFile);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?