program Example;
{$mode ObjFPC}{$H+}
{$coperators On}
uses SysUtils;
type TAZ = String;
// Overloads for Inc can only be declared with both the parameter type
// and the return type being all the the same.
// Note that yes, this "looks" like a function, but it still only works like a procedure.
operator Inc(const AZ: TAZ): TAZ; inline;
begin
Result := AZ + AZ;
end;
// This is also valid.
// Again, while it looks like a function, it works like a procedure.
operator Inc(const A, B: TAZ): TAZ; inline;
begin
Result := A + B;
end;
// You can implement what you want with the + operator, though.
operator +(const AZ: TAZ; const I: Integer): TAZ; inline;
begin
Result := AZ + IntToStr(I);
end;
var S: TAZ = 'Hello!';
begin
Inc(S);
// prints 'Hello!Hello!'
WriteLn(S);
Inc(S, S);
// prints 'Hello!Hello!Hello!Hello!'
WriteLn(S);
// += is not a different operator in FPC, just a combination of + and :=, so the next line works.
S += 55;
// prints 'Hello!Hello!Hello!Hello!55'
WriteLn(S);
end.