The result of a function can be set by setting the result variable: this can be the function identifier or, (only in ObjFPC or Delphi mode) the special Result identifier:
Function MyFunction : Integer;
begin MyFunction:=12; // Return 12 end; |
In Delphi or ObjPas mode, the above can also be coded as:
Function MyFunction : Integer;
begin Result:=12; end; |
As an extension to Delphisyntax, the ObjFPC mode also supports a special extension of the Exit procedure:
Function MyFunction : Integer;
begin Exit(12); end; |
The Exit call sets the result of the function and jumps to the final End of the function declaration block. It can be seen as the equivalent of the C return instruction.