Stretchwickster
Programmer
The following code I wrote produces "Constant expression violates subrange bounds" errors on the lines highlighted in red (in Delphi 6). I've tried playing about with it for a while now but am having no joy. Anyone got any ideas?
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
Code:
const
BYTE_IN_BYTES = 1;
KB_IN_BYTES = BYTE_IN_BYTES * 1024;
MB_IN_BYTES = KB_IN_BYTES * 1024;
GB_IN_BYTES = Int64(MB_IN_BYTES * 1024);
TB_IN_BYTES = Int64(GB_IN_BYTES * 1024);
PB_IN_BYTES = Int64(TB_IN_BYTES * 1024);
function FormatBytes(ASizeInBytes: Int64): String;
begin
case ASizeInBytes of
KB_IN_BYTES..MB_IN_BYTES - 1:
Result := Format('%n KB', [ASizeInBytes / KB_IN_BYTES]);
MB_IN_BYTES..GB_IN_BYTES - 1:
Result := Format('%n MB', [ASizeInBytes / MB_IN_BYTES]);[COLOR=red]
GB_IN_BYTES..TB_IN_BYTES - 1:[/color]
Result := Format('%n GB', [ASizeInBytes / GB_IN_BYTES]);[COLOR=red]
TB_IN_BYTES..PB_IN_BYTES:[/color]
Result := Format('%n TB', [ASizeInBytes / TB_IN_BYTES]);
else
Result := Format('%n bytes', [ASizeInBytes]);
end;
end;
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096