Icon Function and Procedure Implementations

Function and procedure implementations are the executable code in a unit. The implementations of functions/procedures are added to the implementation section of a unit and consist of a variable declaration block, if necessary, followed by a code block:

procedure MyProcedure;
var
   MyVariable: String;
   MyOtherVariable: Integer;
begin
   // Code block
end;

Information The implementation of a function/procedure repeats the same declaration of the function or procedure name followed by the parameters (if present) and return type (for functions). If the implementation does not use the exact same declaration, then the compiler will issue an error.

The variable declarations follow the same declaration rules as the var clause in a unit. Please see the Variable Declarations topic for more information.

A code block consists of a begin keyword followed by a series of statements and an end keyword. The code block that is used in a function or procedure implementation is always terminated with a statement terminator (;). However, code blocks can be nested within other statements, such as conditional if statements. In such cases, please refer to the documentation on the statement to determine if a statement terminator is necessary after the end keyword at the end of a code block.

Returning Results From a Function
Procedures do not return a result, whereas functions do. Every function has an implicit Result variable that can be assigned a value that is returned as the result of the function:

function MyFunction(const MyParameter: String): String;
begin
   Result := 'The parameter value is ' + MyParameter;
end;

The type of the Result variable is determined by the type declaration for the function's return value.
Image