imagedelphipngdelphi-xe3graphicex

How to correct the GraphicEx InChunk() Function?


I am trying to port the GraphicEx component library (for PNG files) from my Delphi 2006 to XE3 (Finally got it) when correcting the basic errors, I got stuck in this error:

"TPNGGraphic.IsChunk" invalid type cast

At lines:

function TPNGGraphic.IsChunk(ChunkType: TChunkType): Boolean;

// determines, independant of the cruxial 5ths bits in each "letter", whether the
// current chunk type in the header is the same as the given chunk type

const
  Mask = not $20202020;

begin
  Result := (Cardinal(FHeader.ChunkType) and Mask) = (Cardinal(ChunkType) and Mask); // <-- this line
end;

Does anyone know what should I do to correct it?


Solution

  • TChunkType is defined as

    type
      TChunkType = array[0..3] of Char;
    

    So the compiler can't cast the TChunkType type into a Cardinal.

    Try changing the definition to

    type
      TChunkType = array[0..3] of AnsiChar;