Recent

Author Topic: Out ...: Array of Something  (Read 382 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 347
Out ...: Array of Something
« on: January 23, 2025, 08:36:15 pm »
while setting length
Code: Pascal  [Select][+][-]
  1. Out intersectionP : Tpoint
would work

Code: Pascal  [Select][+][-]
  1. function .....(....; Out intersectionsPoints : Array of TPoint):boolean;
  2. //....
  3. Setlength(intersectionsPoints, Length(intersectionsPoints)+1);
  4.  

not initialized, type mismatch  ?

instead of length
Code: Pascal  [Select][+][-]
  1. high(intersectionsPoints)-low(intersectionsPoints)+1;
does not make any difference
« Last Edit: January 23, 2025, 08:38:17 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

PascalDragon

  • Hero Member
  • *****
  • Posts: 5858
  • Compiler Developer
Re: Out ...: Array of Something
« Reply #1 on: January 23, 2025, 08:50:09 pm »
I don't understand what you mean. Please show a full example and not just fragments.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10799
  • Debugger - SynEdit - and more
    • wiki
Re: Out ...: Array of Something
« Reply #2 on: January 23, 2025, 08:54:59 pm »
intersectionsPoints  is an "open array" (not a dynamic array).

You can not set the length of an open array. 

Though I am not exactly sure how that works for an "out param". I would assume the out only applies to the content (the TPoints in the array). But not sure.

Declare a dynamic array
Code: Pascal  [Select][+][-]
  1. type TPointArray = array of TPoint;
  2. function foo(out points: TPointArray): boolean;
  3. begin
  4.   SetLength(points, 42);

440bx

  • Hero Member
  • *****
  • Posts: 4998
Re: Out ...: Array of Something
« Reply #3 on: January 23, 2025, 09:08:57 pm »
while setting length
Code: Pascal  [Select][+][-]
  1. Out intersectionP : Tpoint
would work

In addition to what @Martin_fr mentioned, in "intersectionP : Tpoint", that's not an array therefore there is no "high" nor "low" there.  You say SetLength would work but, I have doubts about that, it makes no sense to SetLength something that is not an array.  (didn't even test that because it doesn't make sense.)


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018