Advanced Records in Lazarus / fpc

Note to self: Delphi’s Advanced Records are also available in Lazarus / Free Pascal, but only if they have been explicitly enabled with the modeswitch compiler directive:

unit SomeUnit;

{$mode objfpc}{$H+}{$modeswitch advancedrecords}

interface

type
  TSomeRecord = record
    FSomeField: integer;
    function SomeMethod: integer;
  end;

implementation

function TSomeRecord.SomeMethod: integer;
begin
  Result := FSomeField;
end;

end.

If advancedrecords is not enabled this won’t compile:

Fatal: Syntax error: “END” expected but “FUNCTION” found.