Global Variables and Functions

Parent Previous Next

Global Variables and Functions.

SCRAMBLECODE does not facilitate global variables or functions outside of the class structure. Every field and function must belong to a class. Also the creation of a static class is not supported.


However, a solution does exist, because every instantiated object can use the library function @Main to get access to the Main class. And this means that from anywhere in your program, you can access any public field or function of the Main class as presented in this example:


Class TGlobals

{

 Public String   GlobalField;

 Public Function GlobalFoo(Integer parameter) : Integer { }

}


Class Main

{

 Public TGlobals Globals;


 Public Function Main(Integer x, y, z) : Integer

 {

   Globals.New();

   //....

 }

}


Once you have instantiated the Globals object as a field of the Main class, you are ready to use it from anywhere like this:


 {

    //....

       {

         //...somewhere deep inside your code

         result := @Main().Globals.GlobalFoo(1234);

       }

 }