Is "const var" treated as "by reference"?

If I have a function signature as:

MyFooFunc(aID: Integer; const var aData: MyDataRecord);

Is aData treated by the compiler simply as constant parameter passed by value, or a constant parameter passed by ref

I think a const is always byval.

I’d say: class by ref, struct by value.

I believe “contest var” is same was “var”, but disallows modification.

Ie for a struct, address of struct itself is passed, and changes (would they not be disallowed) would propagate back; for a reference type, the address of the reference would be passed and changing the pointer to a new instance (would the compiler not disallow it) would change the original.

See also https://docs.elementscompiler.com/Oxygene/Members/Methods/#const-var-parameters:

Parameters can optionally be marked as const var . If marked as such, they will be passed in the same fashion as var parameters, discussed above, but cannot be modified within the method.

This option is mainly used for performance reasons, allowing for example a large struct to be passed without causing a second copy to be created on the stack, while still preventing changes to the original value from the caller’s side.

Thank all @Theo69 @FritzW for the attention and kind response. And thank @mh for pointing to the documentation. Yes - const var will be passed by reference.

But!!! For the test case below (Island-Window), I feel the compiler is not working right. Maybe a bug? @ck

For @aData , which is the address of a record, the compiler erroneously thinks it is a method pointer, and thus gives an error. Note ----!!! the compiling will success if simply using var aData: MyData, instead of const var aData: MyData.

Seems in this particular test case, compiler is confused by “const var”

X:\Temp\Island\ConsoleApplication1\ConsoleApplication1\Program.pas(30,26): error E129: Cannot cast from <method pointer> to "^Void"

namespace ConsoleApplication1;
type
  MyData = public record 
    Data1: Double;
    Data2: Single;
    Data3: Byte;
  end;

  Program = class
  public
    class method Main(args: array of String): Int32;
    begin
      var data: MyData;
      data.Data1 := 1;
      data.Data2 := 2;
      data.Data3 := 0;

      DoSomething(data);
      readLn;
    end;
  end;

  method DoSomething(const var aData: MyData); 
  begin
    var lData: MyData;
    memcpy(@lData, ^Void(@aData), sizeOf(MyData));  // Compiler issues error here
    writeLn($"lData.Data1 = {lData.Data1}, lData.Data2 = {lData.Data2}, lData.Data3 = {lData.Data3}")
  end;
end.

Thanks, logged as bugs://82924

bugs://82924 got closed with status fixed.