Xbasic Function Libraries

Description

Xbasic Function Libraries can be used to create Xbasic functions for use in Ajax callbacks in mobile and web applications.

When you build a web component that does Ajax callbacks, the Xbasic function that handles the Ajax callback usually lives in the component definition (in the Xbasic Function Declarations section of the component). Alternatively,function can be globally defined in an .AEX file.

Web projects can also store Xbasic functions in an Xbasic function library. The Web Projects Control Panel has a category called Xbasic, which can be used to manage Xbasic function libraries in a project.

An Xbasic Function Library is a text file with a .a5xbfl extension that is stored in your Web Project. This file contains definitions for one or more Xbasic functions.

Xbasic Function Libraries

To use an Xbasic Function Library in a component you must link the file by specify the Xbasic Linked files property in the component. You can link as many Xbasic Function Library files as you want.

The benefit of using Xbasic Function Library files over defining the Xbasic function directly in the component is that you can share function definitions across multiple components. Xbasic Function Library files are text files, which makes them easy to manage in a source control system (such as Git), and they are easier to work with than .aex files (which provide an alternative method for sharing Xbasic function definitions across multiple components).

If an Xbasic function is defined in both the Xbasic Function Declarations section within a component and also in a linked Xbasic Function Library file, the locally defined function is used.

 Including an Xbasic Function Library in Another Xbasic Function Library

An Xbasic Function Library can be loaded into another Xbasic Function Library or Xbasic script using the compile_Xbasic_function_library() function. For example:

dim lib1 as p = compile_Xbasic_function_library("lib1")

The compile_Xbasic_function_library() function loads an Xbasic Function Library into a dot variable, or "namespace". Functions in the Xbasic Function library are accessed as methods of the dot variable. E.g:

lib1.f1()

See Also