Friday, June 16, 2017

Variable Scopes [AX 2012] :MICROSOFT DYNAMICS VARIABLE SCOPES:

Variable Scopes [AX 2012]

A scope defines the area in which an item can be accessed:
·         Instance variables, declared in class declarations, can be accessed from any methods in the class, and from methods that extend the class.
·         Local variables can be accessed only in the block in which they were defined. All variables created by users have local scope.

Example

X++
class ANewClass
{
    int a;
    
    void aNewMethod()
    {
        int b;
    }
}
A variable, a, is declared in the class and a variable, b, is declared in the aNewMethod method.
As the method is declared in the class block, it can access all variables defined in the class. The aNewMethod method has access to variable a.
Variable b is declared in the aNewMethod method block, so that it can be accessed only from within this block.

A scope defines the area in which an item can be accessed. Variables defined in a class are available to the methods within that class. Variables in methods can be accessed only within the current block, as shown in the following figure.
The class A contains methods b and c and class variables. All methods in the class can see and use all variables in the class.
The method b has some local variables that can only be accessed from within method b.

Method c has some local variables, a function d, and a function e. Functions d and e can be seen only inside method c. As functions d and e are declared inside method c, they have access to their local variables—the local variables in c and the variables in the class, respectively.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...