[fpc-pascal] Setting record values

Ryan Joseph ryan at thealchemistguild.com
Sat Apr 1 05:59:08 CEST 2017

I’ve been using a design pattern in my code which I think is probably pretty stupid so I’d like to make sure. Assume I have a type like TPoint below and I want to set the value I’ll doing something like point := PointMake(x, y). How does the compiler handle this? It probably has to allocate some memory on the heap so shouldn’t I always be setting values using the alternative TPoint.SetPoint? It’s maybe not a big deal but it’s something I’d like to clear up if it’s inefficient.

function PointMake (_x, _y: integer): TPoint;
  result.x := _x;
  result.y := _y;

procedure TPoint.SetPoint (_x, _y: integer);
  x := _x;
  y := _y;

same outcome but which is more efficient?

1) point.SetPoint(x, y);

2) point := PointMake(x, y);

	Ryan Joseph

More information about the fpc-pascal mailing list