Recent

Author Topic: Question about PTArrayByte  (Read 1038 times)

lijinjie

  • New Member
  • *
  • Posts: 18
Question about PTArrayByte
« on: January 21, 2021, 10:26:03 am »
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][+][-]
  1. procedure Image_Binarize(var Bmp:TBitmap;const Thresholde:integer);
  2. var
  3.     p: PByteArray;
  4.     Gray, x, y: Integer;
  5. begin
  6.     Bmp.PixelFormat := pf24Bit;
  7.     randomize;
  8.     for y := 0 to Bmp.Height - 1 do
  9.     begin
  10.         p := Bmp.scanline[y];
  11.         for x := 0 to Bmp.Width - 1 do
  12.         begin
  13.            Gray := Round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x* 3] * 0.11);
  14.             if gray > Thresholde then
  15.             begin
  16.                 p[x * 3] := 255;
  17.                 p[x * 3 + 1] := 255;
  18.                 p[x * 3 + 2] := 255;
  19.             end
  20.             else
  21.             begin
  22.                 p[x * 3] := 0;
  23.                 p[x * 3 + 1] := 0;
  24.                 p[x * 3 + 2] := 0;
  25.             end;
  26.         end;
  27.     end;
  28. end;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Question about PTArrayByte
« Reply #1 on: January 21, 2021, 11:00:58 am »
If you tested with Delphi, did you enable Delphi mode for this piece of code ?

Does it contain {$mode delphi} near the top?

lijinjie

  • New Member
  • *
  • Posts: 18
Re: Question about PTArrayByte
« Reply #2 on: January 21, 2021, 12:34:21 pm »
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.   

bytebites

  • Hero Member
  • *****
  • Posts: 624
Re: Question about PTArrayByte
« Reply #3 on: January 21, 2021, 12:40:46 pm »
{$mode delphi} is required then.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Question about PTArrayByte
« Reply #4 on: January 21, 2021, 12:52:20 pm »
Lazarus is not by default in the most Delphi compatible mode. So yes, it does matter.

lijinjie

  • New Member
  • *
  • Posts: 18
Re: Question about PTArrayByte
« Reply #5 on: January 21, 2021, 01:59:48 pm »
Thank you .. bytebites and marcov.  thumb up. :) :) :)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Question about PTArrayByte
« Reply #6 on: January 21, 2021, 02:44:09 pm »
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][+][-]
  1. Gray := Round(p^[x * 3 + 2] * 0.3 + p^[x * 3 etc.
Delphi mode does the dereferencing automatically behind your back.

lijinjie

  • New Member
  • *
  • Posts: 18
Re: Question about PTArrayByte
« Reply #7 on: January 21, 2021, 04:57:52 pm »
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][+][-]
  1. 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"

 

TinyPortal © 2005-2018