If you tested with Delphi, did you enable Delphi mode for this piece of code ?
Does it contain {$mode delphi} near the top?
Thank you for your reply.
No, there is no "{$mode delphi} " in my code. I just copied the code from Delphi to Lazarus. So {$mode delphi} is not required.
I suppose it's a kind of incompatibility of TByteArray and PTArrayByte between Delphi 7 and Lazarus.
This code is for changing colorful pictures to white and black pictures.