Question about PTArrayByte lazarus / 21-General ---------------------------------------------------------------------- lijinjie · 2021-01-21 09:26 The code works on Delphi well , but it doesn't work on Lazarus. Error: Incompatible types: Got "TByteArray" expected "LongInt" help me! thank you so much!!! //-------------------------------------------------------------------- -------// Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Image_Binarize(var Bmp:TBitmap;const Thresholde:integer);var    p: PByteArray;    Gray, x, y: Integer;begin    Bmp.PixelFormat := pf24Bit;    randomize;    for y := 0 to Bmp.Height - 1 do    begin      p := Bmp.scanline[y];        for x := 0 to Bmp.Width - 1 do        begin           Gray := Round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x* 3] * 0.11);            if gray > Thresholde then             begin                p[x * 3] := 255;                p[x * 3 + 1] := 255;                p[x * 3 + 2] := 255;            end            else            begin                p[x * 3] := 0;                p[x * 3 + 1] := 0;                p[x * 3 + 2] := 0;            end;      end;    end;end; ---------------------------------------------------------------------- marcov · 2021-01-21 10:00 If you tested with Delphi, did you enable Delphi mode for this piece of code ? Does it contain {$mode delphi} near the top? ---------------------------------------------------------------------- lijinjie · 2021-01-21 11:34 Quote from: marcov on January 21, 2021, 11:00:58 amIf 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. ---------------------------------------------------------------------- bytebites · 2021-01-21 11:40 {$mode delphi} is required then. ---------------------------------------------------------------------- marcov · 2021-01-21 11:52 Lazarus is not by default in the most Delphi compatible mode. So yes, it does matter. ---------------------------------------------------------------------- lijinjie · 2021-01-21 12:59 Thank you .. bytebites and marcov.  thumb up. ---------------------------------------------------------------------- howardpc · 2021-01-21 13:44 If you want to use {mode objfpc} you need to manually dereference the pointer p whenever it appears in your code to access the array it points to. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Gray := Round(p^[x * 3 + 2] * 0.3 + p^[x * 3 etc.Delphi mode does the dereferencing automatically behind your back. ---------------------------------------------------------------------- lijinjie · 2021-01-21 15:57 Quote from: howardpc on January 21, 2021, 02:44:09 pmIf you want to use {mode objfpc} you need to manually dereference the pointer p whenever it appears in your code to access the array it points to. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Gray := Round(p^[x * 3 + 2] * 0.3 + p^[x * 3 etc.Delphi mode does the dereferencing automatically behind your back. Good help!! thanks! Then I have to face another issue about the Tbitmap scanline in lazarus .  luckly I found someone asked and got answers  in  "https://forum.lazarus.freepascal.org/index.php?topic=7166.msg44561"