From Clomosy Docs
A function is a group of statements that together perform a task. Every TRObject program has at least one function, which is the program itself, and all the most trivial programs can define additional functions.
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
In TRObject, a function is defined using the function keyword. The general form of a function definition is as follows.
function name(argument(s): type1; argument(s): type2; ...): function_type;
local declarations;
{
...
< statements >
...
result = expression;
}
A function definition in TRObject consists of a function header, local declarations and a function body. The function header consists of the keyword function and a name given to the function. Here are all the parts of a function;
- Arguments − The argument(s) establish the linkage between the calling program and the function identifiers and also called the formal parameters. A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of parameters of a function. Use of such formal parameters is optional. These parameters may have standard data type, user-defined data type or subrange data type.
The formal parameters list appearing in the function statement could be simple or subscripted variables, arrays or structured variables, or subprograms.
- Local declarations − Local declarations refer to the declarations for labels, constants, variables, which are application to the body of function only.
- Result - It is used to terminate the execution of a function and return a specific value to the place where the function was called.
- Function Body − The function body contains a collection of statements that define what the function does.
Example
function Topla(a, b: Integer): Integer; { Result = a + b; } var sonuc: Integer; { sonuc = Topla(5, 10); ShowMessage('Toplam: ' + IntToStr(sonuc)); }