From 40c41d3cbe02aba62feff37fb9069be7eb904063 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 31 Aug 2007 00:03:55 +0000 Subject: [PATCH] Add support for TeraByte and PetaByte in FormatByteNumber. Overcomes a "E2099 Overflow in conversion or arithmetic operation" compiler error by using constants instead of calculating the limits. --- source/helpers.pas | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/helpers.pas b/source/helpers.pas index 932a655a..e8729ffc 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -1956,12 +1956,20 @@ end; } function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload; const - KB = 1024; + {KiloByte} KB = 1024; + {MegaByte} MB = 1048576; + {GigaByte} GB = 1073741824; + {TeraByte} TB = 1099511627776; + {PetaByte} PB = 1125899906842624; begin - if Bytes >= KB *KB *KB then - Result := FormatNumber( Bytes / (KB *KB *KB), Decimals ) + ' GB' - else if Bytes >= KB *KB then - Result := FormatNumber( Bytes / (KB *KB), Decimals ) + ' MB' + if Bytes >= PB then + Result := FormatNumber( Bytes / PB, Decimals ) + ' PB' + else if Bytes >= TB then + Result := FormatNumber( Bytes / TB, Decimals ) + ' TB' + else if Bytes >= GB then + Result := FormatNumber( Bytes / GB, Decimals ) + ' GB' + else if Bytes >= MB then + Result := FormatNumber( Bytes / MB, Decimals ) + ' MB' else if Bytes >= KB then Result := FormatNumber( Bytes / KB, Decimals ) + ' KB' else