helper on property acts like direct field access (read should return copy of record)
FPC 3.3.1 and before
See https://forum.lazarus.freepascal.org/index.php?topic=73330
A property is meant to access the field as if it had a getter function, so that the code can be changed to use a getter and the functionality is kept exactly as is...
In the below the value of FPointX will be updated when using "read FPoint", but not when using GetPoint.
program project1;
{$mode ObjFpc}
{$ModeSwitch AdvancedRecords}
{$ModeSwitch TypeHelpers}
uses
Types;
type
{ TPointHelper }
TPointHelper=record helper for TPoint
procedure SetX(const Value : Longint);
end;
{ TMyClass }
TMyClass=class
private
FPoint : TPoint;
function GetPoint: TPoint;
public
//property Points : TPoint read GetPoint write Fpoint;
property Points : TPoint read FPoint write Fpoint;
end;
{ TMyClass }
function TMyClass.GetPoint: TPoint;
begin
Result:=FPoint;
end;
{ TPointHelper }
procedure TPointHelper.SetX(const Value: Longint);
begin
Self.X := Value;
end;
var
C : TMyClass;
begin
C:=TMyClass.Create;
C.Points:=Point(100,100);
C.Points.SetX(50);
writeln(C.Points.X);
C.Free;
readln;
end.