SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.3
In this example we write
func CloseWindow
oView.win.close()
Where inside the controller class, We uses the oView object to access the form.
Another Example :
59.5. Events Code 685
Ring Documentation, Release 1.5.3
The Event Code
func SayHello
oView {
LineEdit2.setText("Hello "+ LineEdit1.text() )
}
59.6 Keyboard Shortcuts
After selecting one or group of controls
ā€¢ Use the Arrows (Up, Down, Left and Right) to move them around.
ā€¢ Shift + the Arrows (Up, Down, Left and Right) to Resize the controls.
ā€¢ Del button to delete the controls.
ā€¢ CTRL+SHIFT+V to Duplicate the controls.
59.7 Menubar Designer
From the Window properties we can open the Menubar Designer
59.6. Keyboard Shortcuts 686
Ring Documentation, Release 1.5.3
59.8 Window Flags
From the Window properties we can open the Window Flags window.
59.8. Window Flags 687
Ring Documentation, Release 1.5.3
59.9 Entering Items
For some controls like the List Widget we can enter items separated by comma ā€˜,ā€™
59.10 Using Layouts
1. To use layouts, At ļ¬rst add the layout control to the window.
2. Use the window ā€œSet Layoutā€ property to determine the main layout.
3. From the layout properties determine the controls and the layout type.
59.11 More Samples and Tests
Check the folder : ring/applications/formdesigner/tests
Online : https://github.com/ring-lang/ring/tree/master/applications/formdesigner/tests
59.9. Entering Items 688
CHAPTER
SIXTY
SCOPE RULES FOR VARIABLES AND ATTRIBUTES
In this chapter we will learn about scope rules and how Ring ļ¬nd variables.
Also we will learn about conļ¬‚icts and how to solve/avoid them.
The next information are important once you start developing large applications using Ring
These application may uses
ā€¢ Global variables (Try to avoid them)
ā€¢ Classes (Object-Oriented)
ā€¢ braces { } to access objects
ā€¢ Declarative Programming
ā€¢ Natural Programming
60.1 Three Scopes
In Ring we have three scopes :-
1. Public/Global Scope - Each variable you deļ¬ne in the statements part (before functions and classes)
2. Object Scope - When you are inside an object (Inside class method or using { } to access the object )
3. Local Scope - Related to functions and methods
60.2 Deļ¬ning Variables and Variables Access
1. Ring uses lexical scoping, i.e. the scope of the variable is based on where we deļ¬ned the variable.
2. Inside braces { } when you access an object, You will change the current active object scope to this object scope
but you still can access the global scope and the local scope.
3. After the ā€˜Classā€™ keyword and the class name, when you write variable names to be deļ¬ned as attributes, You
still can access the global scope.
In this region (class region - after the class name and before methods) we have
ā€¢ Global Scope ā€”-> The Global Scope
ā€¢ Object Scope ā€”-> The Object Scope
ā€¢ Local Scope ā€”-> The Object Scope
689
Ring Documentation, Release 1.5.3
Note: Since the local scope in the class region point also to the object scope in this region, we can use nested braces
and still have access to the object scope of the class through the local scope.
Tip: You can create windows and controls as attibutes by deļ¬ning them in this region.
Tip: In the class region if you created objects and used braces {} to access them then using self.attribute inside braces
will use the class (not the object that you access) because you have access to the class through the local scope.
4. Function Parameters are automatically deļ¬ned in the local scope.
60.3 How Ring ļ¬nd the variable?
1 - Search First in the Local Scope
if not found !
2 - Search in the Object Scope
if not found !
3 - Search in the public scope
if not found ā€”-> Runtime Error
if found ā€”-> Check if we can do optimization to avoid searching next time (Cache / Pointers for performance).
60.4 Using Object.Attribute
When we use object.attribute the search will be in the object attributes only.
I.e. no search will be done in the local scope or in the global scope for the object attribute.
Note: Using self.attribute will search for the ļ¬rst self before searching for attributes.
60.5 The Self Object
The self object is a reference to the current object that we can use from the class methods.
When we are inside class method and use Self we mean the object that will be created from this class.
Inside the class methods if we used Braces { } this will change the current object scope and self will be changed also
inside braces to reference the object that we access using Braces.
Inside the Class Region (after the class name and before any method) we have access to the object through the object
scope and the local scope also. In this region using Self will always be a reference to the class object. if we used
Braces to change the object scope then used Self inside Braces, Also self will be a reference to the class object (not
the object that we already access using braces) because in the class region we have :-
ā€¢ Global Scope ā€”> Global Scope
ā€¢ Object Scope ā€”> Object Scope
60.3. How Ring ļ¬nd the variable? 690
Ring Documentation, Release 1.5.3
ā€¢ Local Scope ā€”> Object Scope
And using Braces changes the object scope only (not the local scope) and when Ring search for variables it will search
in the Local Scope ļ¬rst so it will ļ¬nd self in the class that we are inside.
60.6 How Ring Deļ¬ne Variables and Attributes
Ring will use the variable name in the Assignment operation
1 - Search using the variable name
2 - If not found ā€”> Avoid the runtime error and deļ¬ne the variable in the current scope
3 - If found ā€”> Use the variable and donā€™t deļ¬ne anything in the current scope
ā€¢ In the global region (before any function or class) the current scope is the global scope.
ā€¢ In the class region (after the class name and before any method) the current scope is the object attributes.
ā€¢ In Functions and methods the current scope is the local scope.
60.7 Conļ¬‚ict between Global Variables and Class Attributes
Look at this example:
name = "test"
o1 = new person
see o1
class person
name
address
phone
In the previous example we have a global variable called ā€˜nameā€™ inside the class person.
when we use the variable ā€˜nameā€™, Ring will start the search operation and will try to ļ¬nd it.
if found ā€”> Use it
if not found ā€”> Deļ¬ne new attribute
But the variable name is a global variable, so it will be found and used!
We will not have the attribute name! added to the object.
Solution (1) - Use the Main Function
func main
name = "test"
o1 = new person
see o1
class person
name
address
phone
Solution (2) - Use special mark for global variable names like $
60.6. How Ring Deļ¬ne Variables and Attributes 691
Ring Documentation, Release 1.5.3
$name = "test"
o1 = new person
see o1
class person
name
address
phone
Solution (3) - Use the AddAttribute() Method
name = "test"
o1 = new person
see o1
class person
AddAttribute(self,"name")
address
phone
Solution (4) - Use self before the attribute name
name = "test"
o1 = new person
see o1
class person
self.name
address
phone
So what is the best solution to this conļ¬‚ict?
1 - Use the $ Mark for global variables
2 - Optional : Try to avoid global variables and use the Main function
In practice i do both of them.
The other solution
ā€¢ Use self before the attribute name or use AddAttribute()
60.8 Conļ¬‚ict between Class Attributes and Local Variables
This conļ¬‚ict may happen when we access the object using braces
Example:
func main
name = "nice"
o1 = new person {name="mahmoud" address="Egypt" phone = 000 }
see o1
class person
name
address
phone
60.8. Conļ¬‚ict between Class Attributes and Local Variables 692
Ring Documentation, Release 1.5.3
In the previous example we have the local variable name.
The value of this variable will be set to ā€œmahmoudā€ instead of the object attribute.
Solution (1) : Just use Self
func main
name = "nice"
o1 = new person {self.name="mahmoud" address="Egypt" phone = 000 }
see o1
class person
name
address
phone
Solution (2) : Change the Local variable name
func main
cName = "nice"
o1 = new person {name="mahmoud" address="Egypt" phone = 000 }
see o1
class person
name
address
phone
Solution (3) : Change Braces and use the Dot operator
func main
name = "nice"
o1 = new person
o1.name ="mahmoud"
o1.address ="Egypt"
o1.phone = 000
see o1
class person
name
address
phone
60.9 Using Braces to access objects inside Class Methods
Remember that we have Three scopes (Local Scope, Object Scope and Global Scope) and when we are inside a class
method, we expect that we have access to the object attributes and methods and this is true until we use braces to
access another object attributes and methods because in this case our object scope will be switched to another object.
new point { test() }
class point
x=10 y=20
func test
see x + nl + y + nl # works fine
myobj = new otherclass {
see name + nl
see x + nl + y + nl # error !
60.9. Using Braces to access objects inside Class Methods 693
Ring Documentation, Release 1.5.3
}
class otherclass
name = "test"
Output:
10
20
test
Line 8 Error (R24) : Using uninitialized variable : x
In method test() in file methodbraceerror.ring
called from line 5 in file methodbraceerror.ring
Now what we will do to solve the previous problem?
Solution (1) : Write the code that access the class attributes outside braces.
new point { test() }
class point
x=10 y=20
func test
see x + nl + y + nl # works fine
myobj = new otherclass {
see name + nl
}
see x + nl + y + nl # Outside braces - works fine
class otherclass
name = "test"
Output:
10
20
test
10
20
Solution (2) : Donā€™t Use Braces
new point { test() }
class point
x=10 y=20
func test
see x + nl + y + nl
myobj = new otherclass
see myobj.name
see x + nl + y + nl
class otherclass
name = "test"
Solution (3) : Copy the self object
We may use this solution if we want to use braces and get access to the class attributes (Just Reading).
60.9. Using Braces to access objects inside Class Methods 694

More Related Content

What's hot

Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Fajar Baskoro
Ā 

What's hot (20)

The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189
Ā 
The Ring programming language version 1.10 book - Part 85 of 212
The Ring programming language version 1.10 book - Part 85 of 212The Ring programming language version 1.10 book - Part 85 of 212
The Ring programming language version 1.10 book - Part 85 of 212
Ā 
The Ring programming language version 1.8 book - Part 79 of 202
The Ring programming language version 1.8 book - Part 79 of 202The Ring programming language version 1.8 book - Part 79 of 202
The Ring programming language version 1.8 book - Part 79 of 202
Ā 
The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196
Ā 
The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84
Ā 
The Ring programming language version 1.5.2 book - Part 69 of 181
The Ring programming language version 1.5.2 book - Part 69 of 181The Ring programming language version 1.5.2 book - Part 69 of 181
The Ring programming language version 1.5.2 book - Part 69 of 181
Ā 
The Ring programming language version 1.5.2 book - Part 70 of 181
The Ring programming language version 1.5.2 book - Part 70 of 181The Ring programming language version 1.5.2 book - Part 70 of 181
The Ring programming language version 1.5.2 book - Part 70 of 181
Ā 
The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189
Ā 
The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212
Ā 
The Ring programming language version 1.9 book - Part 83 of 210
The Ring programming language version 1.9 book - Part 83 of 210The Ring programming language version 1.9 book - Part 83 of 210
The Ring programming language version 1.9 book - Part 83 of 210
Ā 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185
Ā 
The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210
Ā 
The Ring programming language version 1.9 book - Part 85 of 210
The Ring programming language version 1.9 book - Part 85 of 210The Ring programming language version 1.9 book - Part 85 of 210
The Ring programming language version 1.9 book - Part 85 of 210
Ā 
The Ring programming language version 1.5.3 book - Part 83 of 184
The Ring programming language version 1.5.3 book - Part 83 of 184The Ring programming language version 1.5.3 book - Part 83 of 184
The Ring programming language version 1.5.3 book - Part 83 of 184
Ā 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Ā 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Ā 
Object and class in java
Object and class in javaObject and class in java
Object and class in java
Ā 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
Ā 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Ā 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
Ā 

Similar to The Ring programming language version 1.5.3 book - Part 82 of 184

Similar to The Ring programming language version 1.5.3 book - Part 82 of 184 (17)

The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180
Ā 
The Ring programming language version 1.5.2 book - Part 71 of 181
The Ring programming language version 1.5.2 book - Part 71 of 181The Ring programming language version 1.5.2 book - Part 71 of 181
The Ring programming language version 1.5.2 book - Part 71 of 181
Ā 
The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202
Ā 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
Ā 
The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180
Ā 
The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202
Ā 
The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84
Ā 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210
Ā 
The Ring programming language version 1.6 book - Part 74 of 189
The Ring programming language version 1.6 book - Part 74 of 189The Ring programming language version 1.6 book - Part 74 of 189
The Ring programming language version 1.6 book - Part 74 of 189
Ā 
The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180
Ā 
The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31
Ā 
The Ring programming language version 1.3 book - Part 82 of 88
The Ring programming language version 1.3 book - Part 82 of 88The Ring programming language version 1.3 book - Part 82 of 88
The Ring programming language version 1.3 book - Part 82 of 88
Ā 
Module 3 Class and Object.ppt
Module 3 Class and Object.pptModule 3 Class and Object.ppt
Module 3 Class and Object.ppt
Ā 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
Ā 
The Ring programming language version 1.7 book - Part 90 of 196
The Ring programming language version 1.7 book - Part 90 of 196The Ring programming language version 1.7 book - Part 90 of 196
The Ring programming language version 1.7 book - Part 90 of 196
Ā 
The Ring programming language version 1.5.3 book - Part 187 of 194
The Ring programming language version 1.5.3 book - Part 187 of 194The Ring programming language version 1.5.3 book - Part 187 of 194
The Ring programming language version 1.5.3 book - Part 187 of 194
Ā 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
Ā 

More from Mahmoud Samir Fayed

More from Mahmoud Samir Fayed (20)

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212
Ā 
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212
Ā 
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212
Ā 
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212
Ā 
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212
Ā 
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212
Ā 
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212
Ā 
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212
Ā 
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212
Ā 
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212
Ā 
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212
Ā 
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212
Ā 
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212
Ā 
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212
Ā 
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212
Ā 
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212
Ā 
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212
Ā 
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212
Ā 
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212
Ā 
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212
Ā 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(ā˜Žļø+971_581248768%)**%*]'#abortion pills for sale in dubai@
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
Ā 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
Ā 

Recently uploaded (20)

Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Ā 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Ā 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Ā 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Ā 

The Ring programming language version 1.5.3 book - Part 82 of 184

  • 1. Ring Documentation, Release 1.5.3 In this example we write func CloseWindow oView.win.close() Where inside the controller class, We uses the oView object to access the form. Another Example : 59.5. Events Code 685
  • 2. Ring Documentation, Release 1.5.3 The Event Code func SayHello oView { LineEdit2.setText("Hello "+ LineEdit1.text() ) } 59.6 Keyboard Shortcuts After selecting one or group of controls ā€¢ Use the Arrows (Up, Down, Left and Right) to move them around. ā€¢ Shift + the Arrows (Up, Down, Left and Right) to Resize the controls. ā€¢ Del button to delete the controls. ā€¢ CTRL+SHIFT+V to Duplicate the controls. 59.7 Menubar Designer From the Window properties we can open the Menubar Designer 59.6. Keyboard Shortcuts 686
  • 3. Ring Documentation, Release 1.5.3 59.8 Window Flags From the Window properties we can open the Window Flags window. 59.8. Window Flags 687
  • 4. Ring Documentation, Release 1.5.3 59.9 Entering Items For some controls like the List Widget we can enter items separated by comma ā€˜,ā€™ 59.10 Using Layouts 1. To use layouts, At ļ¬rst add the layout control to the window. 2. Use the window ā€œSet Layoutā€ property to determine the main layout. 3. From the layout properties determine the controls and the layout type. 59.11 More Samples and Tests Check the folder : ring/applications/formdesigner/tests Online : https://github.com/ring-lang/ring/tree/master/applications/formdesigner/tests 59.9. Entering Items 688
  • 5. CHAPTER SIXTY SCOPE RULES FOR VARIABLES AND ATTRIBUTES In this chapter we will learn about scope rules and how Ring ļ¬nd variables. Also we will learn about conļ¬‚icts and how to solve/avoid them. The next information are important once you start developing large applications using Ring These application may uses ā€¢ Global variables (Try to avoid them) ā€¢ Classes (Object-Oriented) ā€¢ braces { } to access objects ā€¢ Declarative Programming ā€¢ Natural Programming 60.1 Three Scopes In Ring we have three scopes :- 1. Public/Global Scope - Each variable you deļ¬ne in the statements part (before functions and classes) 2. Object Scope - When you are inside an object (Inside class method or using { } to access the object ) 3. Local Scope - Related to functions and methods 60.2 Deļ¬ning Variables and Variables Access 1. Ring uses lexical scoping, i.e. the scope of the variable is based on where we deļ¬ned the variable. 2. Inside braces { } when you access an object, You will change the current active object scope to this object scope but you still can access the global scope and the local scope. 3. After the ā€˜Classā€™ keyword and the class name, when you write variable names to be deļ¬ned as attributes, You still can access the global scope. In this region (class region - after the class name and before methods) we have ā€¢ Global Scope ā€”-> The Global Scope ā€¢ Object Scope ā€”-> The Object Scope ā€¢ Local Scope ā€”-> The Object Scope 689
  • 6. Ring Documentation, Release 1.5.3 Note: Since the local scope in the class region point also to the object scope in this region, we can use nested braces and still have access to the object scope of the class through the local scope. Tip: You can create windows and controls as attibutes by deļ¬ning them in this region. Tip: In the class region if you created objects and used braces {} to access them then using self.attribute inside braces will use the class (not the object that you access) because you have access to the class through the local scope. 4. Function Parameters are automatically deļ¬ned in the local scope. 60.3 How Ring ļ¬nd the variable? 1 - Search First in the Local Scope if not found ! 2 - Search in the Object Scope if not found ! 3 - Search in the public scope if not found ā€”-> Runtime Error if found ā€”-> Check if we can do optimization to avoid searching next time (Cache / Pointers for performance). 60.4 Using Object.Attribute When we use object.attribute the search will be in the object attributes only. I.e. no search will be done in the local scope or in the global scope for the object attribute. Note: Using self.attribute will search for the ļ¬rst self before searching for attributes. 60.5 The Self Object The self object is a reference to the current object that we can use from the class methods. When we are inside class method and use Self we mean the object that will be created from this class. Inside the class methods if we used Braces { } this will change the current object scope and self will be changed also inside braces to reference the object that we access using Braces. Inside the Class Region (after the class name and before any method) we have access to the object through the object scope and the local scope also. In this region using Self will always be a reference to the class object. if we used Braces to change the object scope then used Self inside Braces, Also self will be a reference to the class object (not the object that we already access using braces) because in the class region we have :- ā€¢ Global Scope ā€”> Global Scope ā€¢ Object Scope ā€”> Object Scope 60.3. How Ring ļ¬nd the variable? 690
  • 7. Ring Documentation, Release 1.5.3 ā€¢ Local Scope ā€”> Object Scope And using Braces changes the object scope only (not the local scope) and when Ring search for variables it will search in the Local Scope ļ¬rst so it will ļ¬nd self in the class that we are inside. 60.6 How Ring Deļ¬ne Variables and Attributes Ring will use the variable name in the Assignment operation 1 - Search using the variable name 2 - If not found ā€”> Avoid the runtime error and deļ¬ne the variable in the current scope 3 - If found ā€”> Use the variable and donā€™t deļ¬ne anything in the current scope ā€¢ In the global region (before any function or class) the current scope is the global scope. ā€¢ In the class region (after the class name and before any method) the current scope is the object attributes. ā€¢ In Functions and methods the current scope is the local scope. 60.7 Conļ¬‚ict between Global Variables and Class Attributes Look at this example: name = "test" o1 = new person see o1 class person name address phone In the previous example we have a global variable called ā€˜nameā€™ inside the class person. when we use the variable ā€˜nameā€™, Ring will start the search operation and will try to ļ¬nd it. if found ā€”> Use it if not found ā€”> Deļ¬ne new attribute But the variable name is a global variable, so it will be found and used! We will not have the attribute name! added to the object. Solution (1) - Use the Main Function func main name = "test" o1 = new person see o1 class person name address phone Solution (2) - Use special mark for global variable names like $ 60.6. How Ring Deļ¬ne Variables and Attributes 691
  • 8. Ring Documentation, Release 1.5.3 $name = "test" o1 = new person see o1 class person name address phone Solution (3) - Use the AddAttribute() Method name = "test" o1 = new person see o1 class person AddAttribute(self,"name") address phone Solution (4) - Use self before the attribute name name = "test" o1 = new person see o1 class person self.name address phone So what is the best solution to this conļ¬‚ict? 1 - Use the $ Mark for global variables 2 - Optional : Try to avoid global variables and use the Main function In practice i do both of them. The other solution ā€¢ Use self before the attribute name or use AddAttribute() 60.8 Conļ¬‚ict between Class Attributes and Local Variables This conļ¬‚ict may happen when we access the object using braces Example: func main name = "nice" o1 = new person {name="mahmoud" address="Egypt" phone = 000 } see o1 class person name address phone 60.8. Conļ¬‚ict between Class Attributes and Local Variables 692
  • 9. Ring Documentation, Release 1.5.3 In the previous example we have the local variable name. The value of this variable will be set to ā€œmahmoudā€ instead of the object attribute. Solution (1) : Just use Self func main name = "nice" o1 = new person {self.name="mahmoud" address="Egypt" phone = 000 } see o1 class person name address phone Solution (2) : Change the Local variable name func main cName = "nice" o1 = new person {name="mahmoud" address="Egypt" phone = 000 } see o1 class person name address phone Solution (3) : Change Braces and use the Dot operator func main name = "nice" o1 = new person o1.name ="mahmoud" o1.address ="Egypt" o1.phone = 000 see o1 class person name address phone 60.9 Using Braces to access objects inside Class Methods Remember that we have Three scopes (Local Scope, Object Scope and Global Scope) and when we are inside a class method, we expect that we have access to the object attributes and methods and this is true until we use braces to access another object attributes and methods because in this case our object scope will be switched to another object. new point { test() } class point x=10 y=20 func test see x + nl + y + nl # works fine myobj = new otherclass { see name + nl see x + nl + y + nl # error ! 60.9. Using Braces to access objects inside Class Methods 693
  • 10. Ring Documentation, Release 1.5.3 } class otherclass name = "test" Output: 10 20 test Line 8 Error (R24) : Using uninitialized variable : x In method test() in file methodbraceerror.ring called from line 5 in file methodbraceerror.ring Now what we will do to solve the previous problem? Solution (1) : Write the code that access the class attributes outside braces. new point { test() } class point x=10 y=20 func test see x + nl + y + nl # works fine myobj = new otherclass { see name + nl } see x + nl + y + nl # Outside braces - works fine class otherclass name = "test" Output: 10 20 test 10 20 Solution (2) : Donā€™t Use Braces new point { test() } class point x=10 y=20 func test see x + nl + y + nl myobj = new otherclass see myobj.name see x + nl + y + nl class otherclass name = "test" Solution (3) : Copy the self object We may use this solution if we want to use braces and get access to the class attributes (Just Reading). 60.9. Using Braces to access objects inside Class Methods 694