9.3 Record operators

FPC supports the Delphi syntax for operators on extended records:

{$mode objfpc}  
{$modeswitch advancedrecords}  
 
Type  
  TComplex = record  
    Re,Im : Double;  
    class operator +(a,b : TComplex) : TComplex;  
  end;  
 
class operator TComplex.+ (a,b : TComplex) : TComplex;  
begin  
  Result.re:=A.re+B.re;  
  Result.im:=A.im+B.im;  
end;

The operators work just as they would if they were defined using the regular FPC syntax for operators. Note that they have the class keyword prefixed.

In Delphi mode, the names of the operators can also be used, similar to the syntax in Delphi:

{$mode delphi}  
Type  
TComplex = record  
Re,Im : Double;  
class operator add(a,b : TComplex) : TComplex;  
end;  
 
class operator TComplex.add (a,b : TComplex) : TComplex;  
begin  
Result.re:=A.re+B.re;  
Result.im:=A.im+B.im;  
end;