Xbasic
Defining a Function with Optional Pointer Variables
Description
To define a function with an optional pointer variable, you must follow the function declaration syntax illustrated below. The parameter = value portion of the declaration is how a default value is defined. NULL_VALUE() is used to assign a NULL value to a pointer.
Examples
The following function examines the parameters sent to it and responds with a message box that says what it received.
function fooFunc as P (param = NULL_VALUE()) 'shows how a function can have either no argument or an optional pointer argument if typeof(param) = "P" then ui_msg_box("Properties of input parameter", properties_enum(param)) else if typeof(param) = "Z" ui_msg_box("","User did not pass in any parameters to the function") 'note: typeof(param) will return "Z" else ui_msg_box("","This function expects either a Pointer argument, or no argument at all. You have specified a " + typeof(param) + " argument") end if
The following code in the Interactive window shows the function in action.
p.name = "selwyn" p.city = "boston" fooFunc(p) fooFunc() fooFunc(23)
See Also