5.7 Global Namespace
References to objects contained in a hierarchical structure starting with “//” ( Root object) are always referenced by the object tree hierarchy, but there is a global namespace that can be referenced from anywhere regardless of the object tree.
Objects located in the global namespace can be referenced directly by name without any period decoration such as //.Form1 .
The global functions built into Biz / Browser as standard are located in the global namespace, so you can use them at any time.
When you load a user-defined function into the global namespace, it becomes available like a built-in global function.
Loading user-defined objects into the global namespace uses the following syntax:
import global_name;
global_name is the name of the object to be the global name. The CRS interpreter executes the import statement as follows:
1. Confirm the global_name.
An error will occur if global_name is duplicated with the class name or global function name.
If global_name has the same name as a user-defined object that is already loaded in the global namespace, do nothing to complete.
2. Generate a URL.
Add the extension “.crs” to global_name and generate the URL so that the CRS script that executed the import statement downloads from the same directory as the downloaded URL.
In the CRS script at http://server/app1/menu.crs
import sample;
Will generate the URL http://server/app1/sample.crs .
3. Download the CRS file from the generated URL and execute it. This download is cached like the Get method.
4. Check the result.
As a result of execution, if none of the package , class , or Record object specified by global_name is generated, an error will occur.
The following description is assumed for the CRS file to be imported .
package sample1 { ← This name is placed in the global namespace.
Number data1;
Number data2;
Function func1 () {
::
}
Function func2 () {
::
}
Function func3 () {
::
}
}
Does not support packages. Substitute with a Record object
If you import such a CRS , you will be able to access it from any scope as follows:
var d1 = sample1.data1;
var d2 = sample1.func2 ();
By loading user-defined objects in the global namespace, you can effectively use common functions and so on.