Protected Variables

On occasion, it may be necessary to limit access to certain variables, preventing access by code outside the variables' scope. This is done by prefacing the variable declaration with the keyword "Protected".

Protected variables (and modules) are not accessible through scope resolution. To put that another way, any variable that is accessible without scope resolution remains accessible, whether protected or not. All use of scope resolution to access a protected variable will fail, even if that variable is accessible without the use of scope resolution. Scope resolution refers to the function, Scope() and the operators "\" and "."

Example:

Using a script application that has one launched module, "LaunchedModule":

{========================== System =================================}
{===================================================================}
(
  System              { Provides access to system library functions };
  Layer               { Provides access to the application layer    };
)
[
  Graphics          Module { Contains user graphics                 };
  WinTitle = "User Application" { Window title                      };
  LaunchedWindow Module "LaunchedWindow.SRC" { launched  child      };
  A = 11;
  Protected B = 22;
]


Init [
  If 1 Main;
  [
    RunningOnVIC = IsVICSession();
  ]
]

Main [
  Window(  0,   0           { Upper left corner   },
         800, 600           { View area           },
         800, 600           { Virtual area        },
         Graphics()         { Start user graphics },
          {65432109876543210}
         0b00010000000110011,
         Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
         7, 1);
]
<
{============================= System\Graphics =====================}
{ This module handles all of the graphics for the application       }
{===================================================================}
Graphics
[
  Handle            { object reference to launched submodule       };
  C = 33            { a plain variable                              };
  Protected D = 44  { a protected variable                          };
]

Main [
  IF ZButton(50, 75, 150, 50, "Launch!", 1);
  [
    Handle = LaunchedWindow();
  ]
  ZText(100, 100,Concat("A is ", PickValid(A, "Invalid")), 5, 0); 
  ZText(100, 120,Concat("B is ", PickValid(B, "Invalid")), 5, 0); 
  
  ZText(100, 150,Concat("C is ", PickValid(C, "Invalid")), 5, 0); 
  ZText(100, 170,Concat("D is ", PickValid(D ,"Invalid")), 5, 0); 
  
  ZText(100,200,Concat("Self()\C is ", PickValid(Self()\C, "Invalid")), 5, 0); 
  ZText(100,220,Concat("Self()\D is ", PickValid(Self()\D, "Invalid")), 5, 0); 

  ZText(100,250,Concat("Handle\E is ", PickValid(Handle\E, "Invalid")), 5, 0); 
  ZText(100,270,Concat("Handle\F is ", PickValid(Handle\F, "Invalid")), 5, 0); 
]
{ End of System\Graphics }
>

And, LaunchedModule as follows:

{=========================== System =================================}
{====================================================================}
(
  System               { Provides access to system library functions };
  Layer                { Provides access to the application layer    };
)
[
  Graphics       Module { Contains user graphics                     };
  WinTitle = "User Application" { Window title                       };
  RunningOnVIC            { TRUE if this is a VIC session              };
  E = 55                     { a plain variable                      };
  Protected F = 66           { a protected variable                  };
]

Init [
  If 1 Main;
  [
    RunningOnVIC = IsVICSession();
  ]
]

Main [
  Window(  0,   0           { Upper left corner   },
         800, 600           { View area           },
         800, 600           { Virtual area        },
         Graphics()         { Start user graphics },
          {65432109876543210}
         0b00010000000110011,
         Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
         0, 1);
]

<
{========================== System\Graphics ========================}
{ This module handles all of the graphics for the application       }
{===================================================================}
Graphics
[
]

Main [
  ZText(100, 100, "Launched window with variables E and F", 5, 0);
]
{ End of System\Graphics }
>

After clicking the Launch! button, the windows will display the following:

Image trimmed to fit this page