A variable used to hold the return value from a function System unit
var Result : Function-Return-Type;
The Result variable is used to hold the result value to be returned by a function.
Delphi automatically creates this variable when the function starts. It is of the same type as the return type of the function.
Result can be used throughout a function as if it were explicitly declared. Whatever its value is upon return from the function is what is passed back.
Result can be seen as equivalent to an out type parameter - where the value upon entry to the function is undefined.
If the $ExtendedSyntax compiler directive is switched Off, then you must use the old return machanism - set the result of a function to a variable of the same name as the function. Such variables can only be assigned to.
Related commands
$ExtendedSyntaxControls some Pascal extension handling
FunctionDefines a subroutine that returns a value
 Download this web site as a Windows program.

Example code : Call a simple function that assigns to Result
  // Get the square of some numbers
  ShowMessageFmt('Square of %d = %d',[2, SquareIt(2)]);
  ShowMessageFmt('Square of %d = %d',[8, SquareIt(8)]);

// Simple function that returns the square of the parameter
function TForm1.SquareIt(value: Integer): Integer;
  // Return the value in the Result variable
  Result := value * value;
Show full unit code
  Square of 2 = 4
  Square of 8 = 64
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page