Re: Is the canvas the only way to draw?
Posted: Wed Jul 21, 2021 2:33 am
Maybe someone has written a number of useful Procedures and saved them as an Include file which you include in your app.
If you've gone and declared all your variables as Global, this would cause havoc if any of the included Procedures contain the same variable names so by using Protected, even if you have made all your variables Global there will be no mix ups.
Normally the variables inside a Procedure are in their own scope but if you use Global, they are exposed.
The results will be 10, 999, 10
Now declare x as Global...
You will see that the value of x now carries over into your main code: 10, 999, 999
Now make x Protected...
Now you see that even though x has been declared as Global, it is not affected by the value of x in the Procedure: 10, 999, 10
If you've gone and declared all your variables as Global, this would cause havoc if any of the included Procedures contain the same variable names so by using Protected, even if you have made all your variables Global there will be no mix ups.
Normally the variables inside a Procedure are in their own scope but if you use Global, they are exposed.
Code: Select all
x=10
Procedure Test()
x=999
Debug x
EndProcedure
Debug x
Test()
Debug x
Now declare x as Global...
Code: Select all
Global x
x=10
Procedure Test()
x=999
Debug x
EndProcedure
Debug x
Test()
Debug x
Now make x Protected...
Code: Select all
x=10
Procedure Test()
Protected x
x=999
Debug x
EndProcedure
Debug x
Test()
Debug x