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 end label__ph_1_ph__: ' 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
$('__ph_1_ph__').innerHTML = 'some value';