0

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?

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
NaN
  • 8,596
  • 20
  • 79
  • 153

1 Answers1

6

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;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • +1 The code is littered with `Char`. Going to need a lot of work. – David Heffernan Mar 07 '13 at 20:15
  • 2
    Woa... I think it's better to declare it as `array[0..3] of byte` since I doubt the intention is to see that _chunk_ as character data. – jachguate Mar 07 '13 at 22:09
  • +1. But @jachguate, such chunks usually contain human-readable section names, IOW, what you call "character data" (or text) and not just 4 bytes of binary data. That is why generally `char[4]` is used (in C), and `array [0..3] of AnsiChar` should be used in Delphi. – Rudy Velthuis Mar 08 '13 at 14:29
  • @Rudy In fact in C char is **the** type for a byte. There is no distinction, as there is in Delphi, between AnsiChar and Byte. – David Heffernan Mar 09 '13 at 08:30
  • It is the type for a byte-sized character, as the name "char" already shows. IOW, the size of char is indeed always one byte. Fact is that in such chunks, you get human-readable names, so AnsiChar is quite correct. – Rudy Velthuis Mar 11 '13 at 07:34