|
<<
Index
>>
|
FutureBasic
|
def fn using <address>
|
|
statement
|
|
Syntax
def fn FunctionName
[(
var1 [,
var2 ...
])
] using fnAddress
Description
This statement associates the name FunctionName
with the routine which is located at the address given by fnAddress
. You can refer to FunctionName
in later parts of your program by using an expression in this form:
fn FunctionName
[(
parm1 [, parm2 ...])
]
This expression will call the function referenced by fnAddress
, and will return the value (if any) that the referenced function returns.
fnAddress
must be a pointer
variable. Before you can call fn FunctionName
, you must make sure that the fnAddress
variable contains the address of a local fn or a def fn <expr>
, as returned by the @fn function. You must not use the address of a label location (as returned by the line
function or the proc
function).
If the name of the function referenced by fnAddress
ends with a type-identifier suffix, then FunctionName
must end with the same type-identifier suffix.
If the function referenced by fnAddress
has a parameter list, then you must include a parameter list (
var1 [, var2...])
in the def fn using <fnAddress>
statement. The number, order, and data types of the parameters in the def fn using <fnAddress>
list must match the number, order, and data types in the parameter list of the referenced function.
The def fn using <fnAddress>
statement is useful in cases where your program must decide at runtime which of several similar functions should be executed in a given instance.
Note
def fn using <fnAddress>
is a "non-executable" statement, which means you cannot change its effect by placing it after then or else (in an if statement), nor by placing it inside any kind of "conditional execution" block such as if...end if, while...wend, for...next, etc. However, you can conditionally include or exclude it by placing it inside a #if...#endif block.
It is possible to choose at run time which function FunctionName
shall be associated with, and even to dynamically change that association from one function to another. This is done by dynamically setting the fnAddress
variable to the addresses of different functions at run time.
See also
local fn; end fn; @fn; def fn <prototype>