See also: function tips, about functions, declaration (parameters etc), programming in QM, class member functions, sub-functions
A user-defined function is a macro that can be called from other macros.
Differences between macros and functions:
By default, functions can be launched by the user or a trigger, like macros. Often you want to prevent launching a function accidentally, because the function is designed to be called from code. Use the Properties dialog, which inserts special line at the beginning of function's text. If the line begins with space and slash ( / ), the function runs only if it is called as function (from macro, other function, or as callback function). If you start it using the Run button, trigger, mac, etc, it does not run. Example (beginning of function's text):
/ function ... ...
If function (or macro, or member function) begins with space, slash and name of other item, then, when you press the Run button, runs that item. This is useful when debugging a function that must be called from code. Example (beginning of function's text):
/test function ... ...
When you launch this function, runs macro "test", that may call this function. If backslash ( \ ) is used, it only prevents starting the function when you press the Run button, but the function can be started using e.g. mac or trigger.
QM compiles functions and macros on demand.
It is possible to change (edit and save) function's code at run time, but changes are not applied while that function (or a function it called) is running. For example, if you edit/save a running function that repeatedly executes code using rep, the changes are applied only when you run the function next time. But if you edit/save a running function that contains a dialog procedure, the changes are applied immediately, because the function is called repeatedly and usually quickly returns.