Local Functions



Define Xbasic and JavaScript functions within a control's definition.


Xbasic and Javascript functions required by a control can be defined at the control level in Local Functions. Locally defined functions are stored with the control, making it easier to create controls with custom JavaScript that can be copied between components or saved in the Control Library.

At run-time, locally defined functions are combined with global functions. That means that if you have defined a local function with the same name as a global function, the local function will overwrite the global function.


Local Xbasic functions can be defined with a control using the Xbasic property in Local Functions.

When defining local Xbasic functions, you need to be careful that you don't use label names that are duplicates of labels used in other function. To get around this potential problem you can use a special placeholder (__ph_x_ph__ where x is any number) in your local function definitions. At run-time, the placeholder gets replaced with a guid. For example:

function myfunc as c ()
ON ERROR GOTO label__ph_1_ph__:
    dim x as c
    ' script here
    ' handle error
end function

When creating Control Library entries that reference local Xbasic, you might want to give the functions unique names so that if you load more than one instance of the Control Library the function in the second and subsequent instance does not overwrite the function in the first instance. This is done by using a special placeholder (__controlId__) in the function name. For example:

function xb__controlId__ as c (e as p)
    ' Displays popup with control ID:
    return "alert('__controlId__');"
end function

When calling the function from an Xbasic script in the control, the control's ID needs to be used. For example, if the control's id is "BUTTON_1", the Xbasic function to call would be:

dim result as c = xbBUTTON_1()


You can also you the special placeholders (__ph_x_ph__) in code to make your Control Library entries more robust. For example:

function xb__controlId__ as c (e as p)
    xb__controlId__ = "$('__ph_1_ph__').innerHTML = '" + js_escape("" + now()) + "';"
end function


Local JavaScript functions can be defined with a control using the Javascript property in Local Functions.

JavaScript functions defined in Local Functions for a control are combined with the global JavaScript for an app at run-time. They behave as if they were defined in the Javascript Functions section of the UX.

As with the Xbasic functions, when you can use the special placeholder __ph_x_ph__ (where "x" is a number -- any number) in your JavaScript functions as a placeholder for the control's ID. For example:

$('__ph_1_ph__').innerHTML = 'some value';

See Also