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()

Distributing Function Libraries as AEX Files 

A directive can be included in the Xbasic Function Library to compile the library into an .aex file at publish time:

'complieaex

If the 'compileaex comment is present anywhere in an Xbasic Function Library, the library will be compiled into an .aex file and published to the application server. The resulting .aex file will have the following file name:

__AAFunctionLibrary_<Xbasic function library name>.aex

At run-time, if a component specifies that a Xbasic Function Library should be loaded, the function library will only be loaded if an associated .aex file is not found.

The benefit of this is minimal for small function library files. However, very large Xbasic Function Library files can take a noticeable amount of time to load and compile. By eliminating this step and loading an .aex file instead you will get a small performance boost.

It is not necessary to add the name of the .aex file to the list of AEX files in Web Project Properties

See Also