📄 unitfunciones.pas
字号:
unit UnitFunciones;
interface
uses Windows, SysUtils;
function ObtenerMejorUnidad(bytes: Int64):String;
function ObtenerMejorUnidadInv(Cadena: String):Int64;
function MyGetFileSize(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 MyGetFileSize(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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -