Link Search Menu Expand Document

5.4 Search for object names

Objects contained in the hierarchical structure starting with “//” ( Root object) have the properties of global variables and can be referenced from any position beyond the variable scope of the script. This section describes in detail how the interpreter searches for the object name described in the script to find the corresponding object.

Base point for object search
CRS programs have the concept of this as well as languages ​​such as JavaScript , JAVA , and C ++ . Object searches are always resolved with this as the starting point. This , which is the base point, is defined as follows.

this immediately after starting Biz / Browser
The “//” object is this .

Object generation block
The object of the block is this .

Form Form1 {
    X = 10; [1]
    Y = 10; [2]
    Button Button1 {
        X = 10; [3]
        Y = 20; [4]
        String str1 {
            Value = "abc"; [5]
        }
    }
}
 

[1]-[2 ] :     this is Form1
[3]-[4 ] :     this is Button1
[5 ] :             this is str1

Event handler this
The object that has the event handler is this

User-defined function this
The object that owns the function is this

Search for objects
Object search is expressed by concatenating names with “.” (Period) starting from this . The name is not case sensitive.

Form1.Button1.str1 = "xyz";

The CRS interpreter searches for and resolves object search expressions that concatenate such names with periods according to the following rules:

1. Search for the var variable from the inside to the outside of the program block.
    The search continues until the run-time context is lost or the block in the current script     file ends.

Runtime context breaks

Button B1 {
    var x1 = 10;     (A)
    X = 10;
    ::
    Function OnTouch (e) {
        ::
        var x2 = 20;     (B)
        var x3 = 20;     (C)
        for ( … ) {
            var x3 = 30;     (D)
            
            x1 = 1; [1]
            x2 = 2; [2]
            x3 = 3; [3]
        }
    }
}

In [1], the execution context differs depending on the Function , so x1 in (A) cannot be detected and the search fails.
In [2], x2 of (B) is searched.
In [3], (D ) detected first is searched among x3 defined in (C) and (D) .

Search in the current script file
If the same structure as the above example is divided into two script files using the Get method, the solution result of the search expression will be different.

Button B1 {
    var x1 = 10;     (A)
    X = 10;
    ::
    Function OnTouch (e) {
        var x2 = 20;     (B)
        var x3 = 20;     (C)
        Get ("for_loop.crs");
    }
}
----- for_loop.crs -----
for ( … ) {
    var x3 = 30;     (D)
    
    x1 = 1; [1]
    x2 = 2; [2]
    x3 = 3; [3]
}

In [1], the search fails as in the previous example.
In [2], the search fails because x2 cannot be detected in for_loop.crs.
[3] searches for (D).

The var variable is resolved at compile time, not at run time, and converted to an intermediate code binary that the interpreter executes. Such script file-dependent name resolution applies only to var variables.

2. Compare with the object name under this.
3. Compare with the property name of this object.
4. Compare with the method name of this object.
5. Compare with the name of this.
6. Compare with the object name of this parent. From then on, it searches for higher-level objects until it finds the appropriate object.
7. Search from the global namespace.

If the above search does not find the target object, the name is unresolved. It also resolves all names concatenated by periods that follow the following rule after resolving the first name.

8. If the resolved name is not an object name (property name, method name, etc.), the search will fail.
9. Finds its child objects starting from the object resolved by the rvalue of the period.
10. Finds the property of the object, starting from the object resolved by the rvalue of the period.
11. Finds a method for that object, starting from the object resolved by the rvalue of the period.

Special object name
“//” can be specifically used as a name to refer to an object at the top of a hierarchy.
“^” Can be specifically used as a name to refer to the parent object of this .