This command is used to create local functions
inside a code to better control its complexity. E.g.
Local functions can access all the variables already defined globally in your code. Also can be recursive.
Variables that appear for first time in a local function are created only in the scope of this function (local variables). These variables cannot be accessed outside the local function that create them. Local variables can be of the following types
The parameters can be of the following types:
We can define default values for simple parameters.
We can call it in code as
The above omits the second parameter and so its default value is assumed (18).
Parameters with default values in the middle of the parameter list can be omitted simply putting only their comma. E.g.
Additionally default values can be defined for array IN parameters too. E.g.
Using symbol & we can declare IN/OUT parameters. e.g.
In the above example, after the execution of TestByRef function, variable b will have the value of 15. Parameter a is declared as IN/OUT parameter. Using IN/OUT parameters we can pass a value to a function (IN) but also we can get a value from it (OUT).
To declare array parameters (IN or IN/OUT) we precede the name of the parameter with keyword arr. E.g.
Array IN parameter:
Array IN/OUT parameter:
Additionally SET command can be used to create array variables locally:
If array a was not created globally before the above function then it is created locally in LocalArr and cannot be accessed outside its scope.
The way to declare automation object parameters is the same as for arrays but using obj instead of arr.
Automation object IN parameter:
Automation object IN/OUT parameter:
Additionally SET command can be used to create automation variables locally:
If object o
was not created globally before the above function then it is created
Function parameters can be declared. Function parameters, as their name imply, accept in their place the name of another local function with the specific parameters interface defined in the declaration of the parameter. For example
The above local function declares two parameters. The first (a) is array (IN/OUT) and the second (Value) is function parameter.
In the declaration of a function parameter we declare its parameters the same way we do for the declaration of any local function. In the above example we declare a function parameter with one simple parameter (elm). MySort will accept in this parameter any local function with an interface of one simple parameter.
The parentheses used to declare the interface of a function parameter help CalcIt language to distinguish a function parameter from a simple one. So, even the function parameter do not use any parameters at all we have to supply at least an empty set of parentheses.
In the body of a local function which declares function parameters, these parameters are used the same way we make calls to local functions. Every time the local function passed to such parameters is called.
The local function passed to a function parameter can be created in any place of the code, before or later of the point of its reference. When the local function is referred before its creation in the code then CalcIt automatically creates a forward declaration. See below on the subject of forward declarations.
Function parameters is a way to create generalized functions customized by a set of routines provided in their parameter list. The real value of this feature is in case of UDF functions, Class constructors and Class public functions.
Similarly to declare the rest of the types as parameters, parameter names are preceded with the following keywords:
NOTE: Parameters of type File, Class and Form are always IN/OUT (BY REFERENCE). The symbol & to denote IN/OUT parameter passing is optional in this case.
We can make forward declarations and implement the function later in our code using the command forward:
See also PROPERTY