[fpc-devel] Operator overloading and {$mode delphi}

Bart bartjunk64 at gmail.com
Sat Apr 13 23:28:44 CEST 2019


Hi,

This example is taken from the documentation:
https://www.freepascal.org/docs-html/ref/refse103.html

{$mode delphi}  //compiles in {$mode objfpc} or {$mode fpc}
{$h+}

Type
  TMyRec = record a,b : integer; end;

operator = (x,y : TMyRec) r : string;

begin
  if (x.a=y.a) and (x.b=y.b) then
    R:='equal'
  else
    R:='differ';
end;

var
  x,y : TMyRec;

begin
  x.a:=1;
  y.a:=1;
  Writeln(x=y);
  x.a:=2;
  y.a:=3;
  Writeln(x=y);
end.

This will compile in {$mode objfpc}, but not in {$mode delphi}:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 3.3.1 [2019/04/03] for i386
...
Compiling test.pas
test.pas(7,17) Fatal: Syntax error, ")" expected but ":" found
Fatal: Compilation aborted
(Same for 3.0.4)

The documentations never states that operator overloading is
impossible in delphi mode.
It even explicitely says
(https://www.freepascal.org/docs-html/ref/refse100.html#x209-23100015.2):
"Remark: When compiling in Delphi mode or Objfpc mode, the result
identifier may be dropped. The result can then be accessed through the
standard Result symbol."

What am I missing?

-- 
Bart



More information about the fpc-devel mailing list