Environmental Objects

When code in a package is compiled, it may need to access features of its local app, appContext, global, currentSession, and currentSchema system variables. Several sets of environmental objects or references are maintained for each process. There is one set for the schema of the process itself and one for each schema from which a package is imported.

The current schema context is maintained for each process. When a method is dispatched that is bound in a schema that differs from the current context, the current context is updated. Similarly, when a method returns, the current context is updated.

Application properties (app) that affect the behavior of a process are reflected across all application objects associated with that process, as they hold state that is relevant to the entire process and all packages running within it (for example, the printer, startupForm, aboutForm, showBubbleHelp, and userSecurityLevel properties, and so on).

If a process is using two packages from different schemas, for example, that process has three app objects (one for each imported package schema and one for the main process). As all application objects should have the same printer, for example, if the printer is changed by any code executed by the process, the change is reflected across all application objects.

If you have two packages (for example, p1 and p2), the second package (p2) imports the first package (p1), and a third schema imports both the p1 and p2 packages, there will be two instance of app for the first package (p1); that is, one in the context of the importing schema and the other in the second p2 package.

Similarly, WebSession objects (currentSession) hold state that is relevant to the entire process and all packages running within it (for example, the sessionId and lastAccessTime properties, and so on). If a process is using two packages from different schemas, for example, that process has three currentSession objects. However, as all session objects should have the same lastAccessTime property value, for example, if the last access time is changed by any code executed by the process, the change is reflected across all Web session objects.

ApplicationContext objects (appContext) hold state that is relevant to the entire process and all packages running within it. If a process is using two packages, for example, that process has three appContext objects.

The appContext system variable enables a package to switch context back to the context of the application that imported the package, using the Object class invokeMethod method. (See also "Calling User Methods from Packages", later in this chapter.)