Recent

Author Topic: How to index a deferanced pointer returned by getstartline  (Read 3007 times)

muscipula

  • Newbie
  • Posts: 3
    • Page 94
How to index a deferanced pointer returned by getstartline
« on: October 20, 2018, 06:23:05 am »
Usually I used scanline but it doesn't seem to work. So I am trying getstartline but I can't seem to index the pointer for example

Code: Pascal  [Select][+][-]
  1.  
  2. rgb_array=array[0..2] of byte;
  3. pixel_array=array[0..integer] of rgb_array;
  4.  
  5. ...
  6.  
  7. pixel_ptr:pixel_array;
  8.  
  9. ...
  10.  
  11. pixel_ptr:=pixel_array(getstartline(y));
  12. pixel_ptr^[x]^[1]:=186;
  13.  

If I then attempt to dereferance pixel_ptr I get an error.

Andrue
Programmer, Astronomer, Amateur radio, Wildlife Trust member, DMX light control

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: How to index a deferanced pointer returned by getstartline
« Reply #1 on: October 20, 2018, 08:55:47 am »
Usually I used scanline but it doesn't seem to work. So I am trying getstartline but I can't seem to index the pointer for example

Code: Pascal  [Select][+][-]
  1.  
  2. rgb_array=array[0..2] of byte;
  3. pixel_array=array[0..integer] of rgb_array;
  4.  
  5. ...
  6.  
  7. pixel_ptr:pixel_array;
  8.  
  9. ...
  10.  
  11. pixel_ptr:=pixel_array(getstartline(y));
  12. pixel_ptr^[x]^[1]:=186;
  13.  

If I then attempt to dereferance pixel_ptr I get an error.

Andrue

Welcome muscipua,

try this approach:

Code: Pascal  [Select][+][-]
  1.  
  2. rgb_array=array[0..2] of byte;
  3. pixel_array=array[0..high(integer)] of rgb_array;
  4. //in pure Pascal definition of static array should have constant boundaries,
  5. //in fact FPC allows compile time accessible values - not clear why not fairly documented.
  6.  
  7. ...
  8.  
  9. pixel_ptr:^pixel_array; //If you want a pointer - first make it!
  10.  
  11. ...
  12.  
  13. pixel_ptr:=pixel_array(getstartline(y));
  14. pixel_ptr^[x][1]:=186; //using pixel_ptr^[x]^[1] is wrong
  15.  

WooBean
« Last Edit: October 20, 2018, 02:14:45 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: How to index a deferanced pointer returned by getstartline
« Reply #2 on: October 20, 2018, 01:34:00 pm »
Correct, but it depends partly on mode and/or {$pointermath settings}
Specialize a type, not a var.

muscipula

  • Newbie
  • Posts: 3
    • Page 94
Re: How to index a deferanced pointer returned by getstartline
« Reply #3 on: October 22, 2018, 03:28:53 pm »
I'll give it a go get back, but ITMT why is the execution code 19mb which in my experience is ridiculous compared to any program I have written with or without symbolic data.

Is it possibly a fat binary?

Andrue
Programmer, Astronomer, Amateur radio, Wildlife Trust member, DMX light control

muscipula

  • Newbie
  • Posts: 3
    • Page 94
Re: How to index a deferanced pointer returned by getstartline
« Reply #4 on: October 22, 2018, 06:36:39 pm »
OK I tried your code, but getlinestart returns pbyte and the compiler is reluctant to allow typecasting as ptr_array.

Andrue



Programmer, Astronomer, Amateur radio, Wildlife Trust member, DMX light control

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: How to index a deferanced pointer returned by getstartline
« Reply #5 on: October 22, 2018, 06:55:00 pm »
You did not say which error. Did you also follow my indication?
There should not be any problem. You are probably doing something wrong but I do not have enough information to help:
what error?
Specialize a type, not a var.

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: How to index a deferanced pointer returned by getstartline
« Reply #6 on: October 22, 2018, 07:16:16 pm »
OK I tried your code, but getlinestart returns pbyte and the compiler is reluctant to allow typecasting as ptr_array.

Andrue
If you want take pbyte into "pixel_ptr" so you can have it as below:

pixel_ptr:=addr(getstartline(y)^);

or

pixel_ptr:=pointer(getstartline(y));

or

pixel_ptr:=@(getstartline(y)^);

===

WooBean
Platforms: Win7/64, Linux Mint Ulyssa/64

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to index a deferanced pointer returned by getstartline
« Reply #7 on: October 22, 2018, 07:28:01 pm »
Type

TMyPixelArray:array[0..whatever] of TRGbPixels;
PMyPixelArray:^TmyPixelArray;

Var
  MyPixels :PMyPixelArray;

Begin

   MyPixels := PMyPixelArray(GetStartLine); //Notice I typed cast with a type not an variable.

  Somewhere in code ladn
 
 MyPixels^[ x ].blue …..
etc...
 You should get that.

Btw.
  THe EXE file contains the Debug file attached to the EXE, it isn't really that large..
   Go into your Project settings to the Debugger setup and tell it to use external file for the debugger..


« Last Edit: October 24, 2018, 10:14:32 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018