Global Scripts


Alpha Anywhere allows you to create Global Scripts. These are scripts that are not attached to any form buttons or events. Global Scripts are shown in the Code page of the Control Panel and they can be played back directly from the Control Panel by double clicking on the script name. Global Scripts can also be called by another script using the SCRIPT_PLAY() or SCRIPT_SPAWN() command. For example, the script that is attached to a button on a form might include this command:

script_play("print report")

How to Define a Global Script

To define a Global Script, select the Code tab on the Control Panel and click the New button. Check "Script" on the New Object dialog box. In the next dialog box, specify the script name, and indicate whether you want to define the script using the Action Scripting Editor, or the Code Editor.

How to Share Global Scripts

Like global functions, global scripts that you define in one database can be used in another database if you compile them into an .AEX file and place the .AEX in the addins_installed folder under the Alpha Anywhere program directory.

Alpha Software recommends that you first transform global scripts that you want to share into global functions. This will result in better performance and fewer limitations.

The Autoexec Global Script

If you create a Global Script called "Autoexec", this script will be played back automatically when you open the database. The "Autoexec" script is very useful for setting up your application. For example, you might want to hide the control panel and show the "Main Menu" form when a user loads a particular database. You could do this by creating an "Autoexec" script with these commands:

:form.view("main menu")

Alpha Anywhere adds the "OnDatabaseClose" and "CanDatabaseClose" scripts. Just as the Autoexec script automatically runs when a database is first opened, the OnDatabaseClose script automatically runs when the database is closed. The CanDatabaseClose script automatically runs when the user tries to close the database. If this script calls the CANCEL() function, the database is not closed. In addition to these two specially named scripts, you can register code to be run before the database is closed, and when the database is closed using the ON_DATABASE_EXIT() and CAN_DATABASE_EXIT() functions.


Desktop applications only. Not available in Community Edition.

See Also