I define the types of graphic files by their headers, for example:

var stream : TFileStream; buff : int64; … stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyRead); stream.Read(buff, sizeof(buff)); stream.Free; case (buff and $FFFFFFFF) of $E0FFD8FF : result := 'JPEG IMAGE'; $E2FFD8FF : result := 'JPEG CANNON EOS JPEG FILE'; … 

Using http://www.filesignatures.net/index.php?page=all&order=EXT&alpha=P .
But when I substitute the signature for "*. * Png" - $0A1A0A0D474E5089 (in 8 bytes ) in case :

 case buff of $0A1A0A0D474E5089 : result := 'PNG'; end 

I have an error:

Constant expression violates subrange bounds

How to be in this case?

    1 answer 1

    As stated in the documentation, the limit is 32 bits: http://docwiki.embarcadero.com/RADStudio/XE3/en/Declarations_and_Statements#Case_Statements

    smaller than 32 bits (string types and ordinals larger than 32 bits are invalid)

    Output - do a cast to 32 bits or write in an else block

     case (buff and $FFFFFFFF) of $E0FFD8FF: Result := 'JPEG IMAGE'; $E2FFD8FF: Result := 'JPEG CANNON EOS JPEG FILE'; $474E5089: if buff shr 32 = $0A1A0A0D then Result := 'PNG'; // <-- вариант номер 1 else if buff = $0A1A0A0D474E5089 then // <-- вариант номер 2 Result := 'PNG'; end;