Advanced records as function parameters lazarus / 62-General ---------------------------------------------------------------------- avk · 2020-09-30 16:53 Hi! A simple test Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program adv_rec_test;{$mode objfpc}{$H+}{$MODESWITCH ADVANCEDRECORDS}uses  SysUtils;type  TIntArray = array of Integer;  TTest = record    Data: TIntArray;    function IsSame(const aRec: TTest): Boolean;    function IsSame2(constref aRec: TTest): Boolean;  end; function TTest.IsSame(const aRec: TTest): Boolean;begin  WriteLn('IsSame:');  WriteLn('@aRec = ', Format('$%p', [@aRec]));  WriteLn('@Self = ', Format('$%p', [@Self]));  if @aRec = @Self then    exit(True);  Result := False;end; function TTest.IsSame2(constref aRec: TTest): Boolean;begin  WriteLn('IsSame2:');  WriteLn('@aRec = ', Format('$%p', [@aRec]));  WriteLn('@Self = ', Format('$%p', [@Self]));  if @aRec = @Self then    exit(True);  Result := False;end; var  t: TTest; begin  t.Data := [1, 2, 3, 4];  WriteLn(t.IsSame(t));  WriteLn(t.IsSame2(t));end.  gives an interesting result for i386_win-32(fpc-3.3.1r46955): Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IsSame:@aRec = $0141FF48@Self = $00419010FALSEIsSame2:@aRec = $00419010@Self = $00419010TRUE  What am I missing? ---------------------------------------------------------------------- Martin_fr · 2020-09-30 17:10 If you pass a record (advanced or not) as parameter, then this is passing the actual data => you hand over a copy. Records (unlike classes) are not passed by reference. Though apparently advanced record in "self" is passed by ref (and needs to be => it is a "var param") "const arec: TTEst" allows the compiler to choose between copy or ref. Apparently for the specific record a copy was passed. "constref" forces a ref. (same as "var param") ---------------------------------------------------------------------- WooBean · 2020-09-30 17:13 I think the answer is here: https://www.freepascal.org/docs- html/ref/refsu66.html It is not limited to advanced records or a particular target platform. WB ---------------------------------------------------------------------- avk · 2020-09-30 18:27 Thanks to everyone who answered, the question was pretty silly. Hence the simple conclusion: at night a person should sleep.