Global Variables

Global variables can be used by HEScript, PHP, JavaScript scripts to share data and store values in the application. Each HEScript script is run separately by a single engine, so they cannot share variables: you need to use global variables if you want to share data between two scripts for instance.

You can manage global variables using:

Info

They can replace cookies in your JavaScript or PHP code. See the cookies topic too.

Properties

Global variable names are unique and must contain only alphanumeric characters (without any space). In general, your global variables should never begin with "HE" because such variables may be used internally by ExeOutput for PHP.

Global variables may be persistent or temporary; a persistent variable is stored in the application, in other words the variable and its value are saved in the application's state file and loaded the next time the application is run. A temporary variable will exist only for the current session. You determine whether a variable is persistent or not when you set its value using the SetGlobalVar method.

Global variables are not shared between several running instances of an application, but you can force all of the instances to have the same global variables by calling the SynchronizeGlobalVar function.

List of pre-defined global variables

Warning

Not all global variables are available in console applications: only HEPublicationFile and HEPublicationPath are used. Likewise, it is not possible to change the values of global variables in console applications.

Global Variable Name Description
HEPublicationFile The full path to the application's .exe file (including filename)
HEPublicationPath The full path to the folder that contains the application's .exe file (no filename). It will always include the path trailing backslash (e.g. C: MyPath** **).
HELasterrormessage When an error occurs, this variable contains the error message.
DefWinTitle The title of the main window.
HomePage The index page's filename.
HEPubStorageLocation The path where the application stores its data. You can customize it.
HEPubTempPath The path to a temporary location where the application stores its external files temporarily. This will change each time.
HEPHPDataPath The path to the virtual cache folder used for PHP files (includes the last trailing backslash).
HEPublicationDiskInfo Contains the device ID returned by Windows of the USB disk on which the application EXE lies
CurPageTitle The title of the page which is currently displayed.
FwdButtonEnabled Is the forward button enabled? (true/false)
BackButtonEnabled Is the back button enabled? (true/false)
HEStartCurrentDirectory The current working directory (when you launch the EXE). Read this global variable instead of calling getcwd in PHP.
HEPublicationOnUSB Boolean (0 or 1). Tells you whether the application is on a USB drive or not. In order to be used, GetManualHardwareID(1) must be invoked first. For example, using this global variable lets you decide whether an application may be run or not.
isappterminated Only accessible from PHP. This global variable is set to "1" when the application is terminated. Useful for an infinite loop in PHP to find out whether it should exit. See sample below
hesuppressjsdlg Boolean (0 or 1). Lets you disable all dialog boxes displayed by JavaScript functions such as alert()

PHP Example to read a global variable

<?php
$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');

$file = $storagelocation.'myfile1.txt';

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fclose($fp); 
?>

HEScript

procedure OnStartMainWindow;
begin
 // When the main window is going to be displayed (just before the homepage is shown).
 SetGlobalVar("hesuppressjsdlg", "1", false);
end;

Loops

For instance, use this PHP code in your loops:

if (exo_getglobalvariable("isappterminated", "0") == "1") break;

See also: JavaScript sample with global variables

How to call HEScript procedures/functions?