SRL Archive - Bugs

Type mismatch when using InvertTPA


Coh3n

2010-06-30 18:57:00

Well this was first brought to my attention from this thread, so I decided to try it out.

program new;

var
a, b: TPointArray;

begin
a := [Point(0, 0), Point(0, 1), Point(1, 1)];
b := InvertTPA(a);

for i := High(b) downto 0
writeln('Point('+IntToStr(b[i].x)+', '+IntToStr(b[i].y)+')');
end.
Returns a type mismatch on this line:

b := InvertTPA(a);
Not sure if it's Simba or the interpreter.

Ideas?

lordsaturn

2010-06-30 19:16:07

Yeah here's an idea
procedure InvertTPA(var a: TPointArray)

Coh3n

2010-06-30 19:21:56

From: lordsaturn
Yeah here's an idea
procedure InvertTPA(var a: TPointArray)

Lmao, wow. :duh:

In that case, why isn't it a function?

Gu3st...

2010-06-30 19:23:52

procedure? Why?
marpis, RM, Coh3n and me all though it was a function.. Makes more sense that way :P

NCDS

2010-06-30 20:37:58

From: Zyt3x
procedure? Why?
marpis, RM, Coh3n and me all though it was a function.. Makes more sense that way :P


It goes along with the sorting functions like this though.

Wizzup?

2010-07-01 08:06:01

There's actually a big difference.


procedure InvertTPA(var a: TPointArray);

This inverts the array that you pass. It does not copy the array, it directly affects 'a'.


function InvertTPA(a: TPointArray): TPointArray;

This copies array a, inverts it, and returns the new array as result. (a is left unchanged)

Gu3st...

2010-07-01 09:38:08

From: Wizzup?
There's actually a big difference.


procedure InvertTPA(var a: TPointArray);

This inverts the array that you pass. It does not copy the array, it directly affects 'a'.


function InvertTPA(a: TPointArray): TPointArray;

This copies array a, inverts it, and returns the new array as result. (a is left unchanged)
That's a good point why it should be a function

That's what you guys do in GreyscaleBitmap() and PosterizeBitmap() ;)

Wizzup?

2010-07-01 09:40:03

It was made a procedure exactly for the reasons I named…

nielsie95

2010-07-01 09:41:28

Why'd you want to use the old points after sorting them?

Gu3st...

2010-07-01 09:45:21

Why make it so that some are functions and some are procedures? That will only cause confusion

Wizzup?

2010-07-01 10:08:14

From: Zyt3x
Why make it so that some are functions and some are procedures? That will only cause confusion


Because sometimes you don't want it to alter the original points and in other cases you do want it to alter the original points.

Gu3st...

2010-07-01 10:21:07

From: Wizzup?
Because sometimes you don't want it to alter the original points and in other cases you do want it to alter the original points.
Fine..