Chapter 5. The Application class

Table of Contents

5.1. Class Definition
5.2. Construction and Destruction
5.3. Handling Events
5.4. Timers
5.5. Menus

The Application class is the parent class for all the applications you create with the New button in the Scripting option of the Properties window. It provides an environment that makes it easy for you to program for changes and events. It also allows you to set up timers, and to add menus for your scripts to the DataHub's pop-up system tray menu. This chapter contains an overview of the Application.g file, where the Application class and its methods are defined.

5.1. Class Definition

This code defines the base Application class:

/* A base application class that keeps track of change functions
   and removes them when the object is destroyed */

if (undefined_p(Application) || !class_p(Application))
{
    class Application
    {
        _ChangeFunctions;
        _TimerIDs;
        _MenuActions;
        _SubMenus;
    static:
        _Instances;
        _MenuItemID = 20000;
        _MenuItems;
        _TraySubmenu;
        _AllMenuActions;
        _TrayMenuPosition = 6;
    }
}

Before defining the class, we test to see if it already exists, using the Gamma predicates undefined_p and class_p functions in an if statement. We want only a single instance of the class so that there is only one copy of the _Instances static variable in the system. This _Instances variable tracks the currently loaded applications, and we do not want several different copies of it floating about.

The instance variable _ChangeFunctions is a list of all the change functions that are defined by the class's .OnChange method. The _TimerIDs, _MenuActions, and _Submenus instance variables are similar lists for any timer IDs, menu actions, and custom submenus that may be defined for the class.