SlideShare a Scribd company logo
Ring Documentation, Release 1.7
y: 20.000000
z: 30.000000
70.27 ringvm_give() function
Using the ringvm_give() function we can redefine the behavior of the Give command
Example:
see "Name: " give name
see "Hello " + name
func ringvm_give
see "Mahmoud" + nl
return "Mahmoud"
Output:
Name: Mahmoud
Hello Mahmoud
70.27. ringvm_give() function 812
CHAPTER
SEVENTYONE
THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER
In this chapter we will learn about the Trace Library and the Interactive Debugger
71.1 Loading the Trace library
To start using the Trace library, We must load it first!
load "tracelib.ring"
71.2 Trace All Events
The next example demonstrates the Trace library usage to trace all events.
# Trace All Events
trace(:AllEvents)
see "Hello, world!" + nl
see "Welcome" + nl
see "How are you?" +nl
mytest()
new myclass { mymethod() }
func mytest
see "Message from mytest" + nl
class myclass
func mymethod
see "Message from mymethod" + nl
71.3 Trace control flow between functions
The next example demonstrates the Trace library usage to trace the control flow between functions.
Trace(:Functions)
test1()
813
Ring Documentation, Release 1.7
func test1
see :test1 + nl
test2()
func test2
see :test2 + nl
see test3() + nl
func test3
see :test3 + nl
return "test 3 output"
71.4 Pass Error
The next example demonstrates the Trace library usage to pass an error!
Trace(:PassError)
test1()
func test1
x = 10
see :test1 + nl
test2() # Runtime Error!
see "We can continue!"
71.5 Interactive Debugger
The next example demonstrates the Trace library usage to use the Interactive Debugger
Trace(:Debugger)
test1()
see "good bye!" + nl
func test1
x = 10
see :test1 + nl
t = 12
test2() # Runtime Error!
see "After Error!" +nl
see "t = " see t see nl
see "x = " see x see nl
71.6 Execute Program Line by Line
The next example demonstrates the Trace library usage to execute the program line by line!
Trace(:LineByLine)
test1()
71.4. Pass Error 814
Ring Documentation, Release 1.7
func test1
x = 10
see :test1 + nl
t = 12
test2()
see "After Error!" +nl
see "t = " + t + nl
71.7 BreakPoint
The next example demonstrates the Trace library usage to stop at a breakpoint!
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
71.8 Disable BreakPoints
The next example demonstrates the Trace library usage and how to disable the Breakpoints!
NoBreakPoints()
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
71.9 Using the Interactive Debugger
The next example uses a Breakpoint to open the Interactive Debugger!
load "tracelib.ring"
test1()
func test1
x = 10
see :test1 + nl
t = 12
71.7. BreakPoint 815
Ring Documentation, Release 1.7
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
Screen Shots:
We have the Interactive Debugger at the Breakpoint!
We can print the variables values
We can change the variables values then continue execution
71.9. Using the Interactive Debugger 816
Ring Documentation, Release 1.7
We can run the Interactive Debugger in the Output Window
71.9. Using the Interactive Debugger 817
CHAPTER
SEVENTYTWO
EMBEDDING RING IN RING
In this chapter we will learn about embedding Ring in Ring programs and applications.
72.1 Embedding Ring in Ring without sharing the State
From Ring 1.0 we already have functions for embedding Ring in the C language. Also we can execute Ring code
inside Ring programs using the eval() function. In this release we provide functions for embedding Ring in Ring
programs without sharing the state.
Advantages:
1. Quick integration for Ring programs and applications together without conflicts.
2. Execute and run Ring code in safe environments that we can trace.
Example:
pState = ring_state_init()
ring_state_runcode(pState,"See 'Hello, World!'+nl")
ring_state_runcode(pState,"x = 10")
pState2 = ring_state_init()
ring_state_runcode(pState2,"See 'Hello, World!'+nl")
ring_state_runcode(pState2,"x = 20")
ring_state_runcode(pState,"see x +nl")
ring_state_runcode(pState2,"see x +nl")
v1 = ring_state_findvar(pState,"x")
v2 = ring_state_findvar(pState2,"x")
see v1[3] + nl
see V2[3] + nl
ring_state_delete(pState)
ring_state_delete(pState2)
Output:
Hello, World!
Hello, World!
10
20
10
20
818
Ring Documentation, Release 1.7
72.2 Serial Execution of Programs
We can execute application after another application using ring_state_main()
Example:
chdir(exefolder()+"/../applications/formdesigner")
ring_state_main('formdesigner.ring')
chdir(exefolder()+"/../applications/cards")
ring_state_main('cards.ring')
72.3 ring_state_setvar()
Using ring_state_setvar() we can set variables value
The value could be (String, Number, List or C Pointer)
We need this function to quickly pass lists and C pointers to the Sub Ring Environment
Syntax:
ring_state_setvar(oState,cVariableName,Value)
Example:
load "guilib.ring"
myapp = null
win = null
func main
myapp = new qApp {
win = new qWidget() {
setWindowTitle("Advanced Example on using ring_state_setvar()")
move(100,100)
resize(600,400)
new qPushButton(win) {
setText("Test")
setClickEvent("Test()")
}
# We need this because using load 'guilib.ring' in the sub environment
# Will create timers by Qt and closing the window will not be enough
# To close the application
oFilter = new qAllEvents(win)
oFilter.setCloseEvent("myapp.quit()")
win.installeventfilter(oFilter)
show()
}
exec()
}
func test
pState = ring_state_init()
ring_state_runcode(pstate,"load 'guilib.ring'")
ring_state_runcode(pState,"x = NULL")
# Pass String
ring_state_setvar(pState,"x","hello")
72.2. Serial Execution of Programs 819
Ring Documentation, Release 1.7
ring_state_runcode(pState,"? x")
# Pass Number
ring_state_setvar(pState,"x",100)
ring_state_runcode(pState,"? x")
# Pass List
ring_state_setvar(pState,"x",["one","two","three"])
ring_state_runcode(pState,"? x")
# Pass Object
# We can't pass the Ring Object (win)
# Because Objects store pointers to the Class Information
# And the class is related to the Parent Ring Environment
# And the sub Ring environment can't access it
# But we can pass C pointers like win.pObject
ring_state_setvar(pState,"x",win.pObject)
# Now we create the object again but using the same C pointer
# So we have access to the Same window in the parent Ring enviroment
ring_state_runcode(pState,"
new qWidget {
pObject = x
setwindowtitle('Message from the Sub Ring Environment')
}
")
ring_state_delete(pState)
72.4 ring_state_new() and ring_state_mainfile()
Using ring_state_new() and ring_state_mainfile() we can run Ring programs from Ring programs
But unlike ring_state_main(), Here we can control when to delete the Ring state!
This is important when we run GUI programs from GUI programs
Because they will share the GUI Library (RingQt), And In this case the caller will call
qApp.Exec()
So the sub program, will not stop and will return to the Main program
Here deleting the State of the sub programs will lead to a problem when we run the sub program events
So keeping the state is important for sub GUI programs hosted in GUI programs.
Example:
load "guilib.ring"
func main
new qApp {
win = new qWidget() {
setWindowTitle("Test ring_state_mainfile()")
resize(400,400) move(100,100)
btn = new qPushButton(Win) {
settext("test")
setclickevent("mytest()")
}
show()
}
exec()
}
72.4. ring_state_new() and ring_state_mainfile() 820
Ring Documentation, Release 1.7
func mytest
pState = ring_state_new()
ring_state_mainfile(pState,"runprogram.ring")
# Here we don't delete the state if we will run GUI application
# So we can run the GUI application events
// ring_state_delete(pState)
If you will use this feature, remember to update the previous example based on your application needs
So you can call ring_state_delete() at some point to avoid the memory leak!
72.4. ring_state_new() and ring_state_mainfile() 821

More Related Content

PDF
The Ring programming language version 1.8 book - Part 88 of 202
PPTX
Reacting with ReactiveUI
PDF
The Ring programming language version 1.10 book - Part 101 of 212
PDF
Actor Concurrency
PDF
The Ring programming language version 1.7 book - Part 91 of 196
PDF
The Ring programming language version 1.5.1 book - Part 37 of 180
PDF
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
PDF
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.8 book - Part 88 of 202
Reacting with ReactiveUI
The Ring programming language version 1.10 book - Part 101 of 212
Actor Concurrency
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.5.1 book - Part 37 of 180
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
The Ring programming language version 1.6 book - Part 81 of 189

What's hot (20)

PDF
The Ring programming language version 1.5.1 book - Part 74 of 180
PPTX
PPTX
Theorical 1
PDF
Primi passi con Project Tango
PPTX
Fine grain process control 2nd nov
PPS
Unbounded
PPT
Unbounded
PPTX
Teorical 1
PDF
The evolution of java script asynchronous calls
PPTX
From clever code to better code
PDF
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
PDF
Java Practical File Diploma
PPT
Swiss army knife Spring
PDF
React new features and intro to Hooks
PDF
Spring Transaction
PDF
React hooks beyond hype
PPTX
Java Script Promise
PDF
The Ring programming language version 1.8 book - Part 86 of 202
PDF
Think Async: Asynchronous Patterns in NodeJS
The Ring programming language version 1.5.1 book - Part 74 of 180
Theorical 1
Primi passi con Project Tango
Fine grain process control 2nd nov
Unbounded
Unbounded
Teorical 1
The evolution of java script asynchronous calls
From clever code to better code
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
Java Practical File Diploma
Swiss army knife Spring
React new features and intro to Hooks
Spring Transaction
React hooks beyond hype
Java Script Promise
The Ring programming language version 1.8 book - Part 86 of 202
Think Async: Asynchronous Patterns in NodeJS
Ad

Similar to The Ring programming language version 1.7 book - Part 85 of 196 (20)

PDF
The Ring programming language version 1.5.3 book - Part 89 of 184
PDF
The Ring programming language version 1.9 book - Part 92 of 210
PDF
The Ring programming language version 1.5.1 book - Part 12 of 180
PDF
The Ring programming language version 1.7 book - Part 7 of 196
PDF
The Ring programming language version 1.3 book - Part 7 of 88
PDF
The Ring programming language version 1.6 book - Part 83 of 189
PDF
The Ring programming language version 1.6 book - Part 41 of 189
PDF
The Ring programming language version 1.6 book - Part 184 of 189
PDF
The Ring programming language version 1.6 book - Part 7 of 189
PDF
The Ring programming language version 1.5.2 book - Part 13 of 181
PDF
The Ring programming language version 1.10 book - Part 21 of 212
PDF
The Ring programming language version 1.5.4 book - Part 14 of 185
PDF
The Ring programming language version 1.7 book - Part 92 of 196
PDF
The Ring programming language version 1.10 book - Part 95 of 212
PDF
The Ring programming language version 1.10 book - Part 12 of 212
PDF
The Ring programming language version 1.10 book - Part 102 of 212
PDF
The Ring programming language version 1.5.3 book - Part 85 of 184
PDF
The Ring programming language version 1.10 book - Part 20 of 212
PDF
The Ring programming language version 1.9 book - Part 99 of 210
PDF
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.6 book - Part 83 of 189
The Ring programming language version 1.6 book - Part 41 of 189
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 7 of 189
The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.10 book - Part 21 of 212
The Ring programming language version 1.5.4 book - Part 14 of 185
The Ring programming language version 1.7 book - Part 92 of 196
The Ring programming language version 1.10 book - Part 95 of 212
The Ring programming language version 1.10 book - Part 12 of 212
The Ring programming language version 1.10 book - Part 102 of 212
The Ring programming language version 1.5.3 book - Part 85 of 184
The Ring programming language version 1.10 book - Part 20 of 212
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.8 book - Part 7 of 202
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 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 210 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 205 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 203 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 200 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 197 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 194 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

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I

The Ring programming language version 1.7 book - Part 85 of 196

  • 1. Ring Documentation, Release 1.7 y: 20.000000 z: 30.000000 70.27 ringvm_give() function Using the ringvm_give() function we can redefine the behavior of the Give command Example: see "Name: " give name see "Hello " + name func ringvm_give see "Mahmoud" + nl return "Mahmoud" Output: Name: Mahmoud Hello Mahmoud 70.27. ringvm_give() function 812
  • 2. CHAPTER SEVENTYONE THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER In this chapter we will learn about the Trace Library and the Interactive Debugger 71.1 Loading the Trace library To start using the Trace library, We must load it first! load "tracelib.ring" 71.2 Trace All Events The next example demonstrates the Trace library usage to trace all events. # Trace All Events trace(:AllEvents) see "Hello, world!" + nl see "Welcome" + nl see "How are you?" +nl mytest() new myclass { mymethod() } func mytest see "Message from mytest" + nl class myclass func mymethod see "Message from mymethod" + nl 71.3 Trace control flow between functions The next example demonstrates the Trace library usage to trace the control flow between functions. Trace(:Functions) test1() 813
  • 3. Ring Documentation, Release 1.7 func test1 see :test1 + nl test2() func test2 see :test2 + nl see test3() + nl func test3 see :test3 + nl return "test 3 output" 71.4 Pass Error The next example demonstrates the Trace library usage to pass an error! Trace(:PassError) test1() func test1 x = 10 see :test1 + nl test2() # Runtime Error! see "We can continue!" 71.5 Interactive Debugger The next example demonstrates the Trace library usage to use the Interactive Debugger Trace(:Debugger) test1() see "good bye!" + nl func test1 x = 10 see :test1 + nl t = 12 test2() # Runtime Error! see "After Error!" +nl see "t = " see t see nl see "x = " see x see nl 71.6 Execute Program Line by Line The next example demonstrates the Trace library usage to execute the program line by line! Trace(:LineByLine) test1() 71.4. Pass Error 814
  • 4. Ring Documentation, Release 1.7 func test1 x = 10 see :test1 + nl t = 12 test2() see "After Error!" +nl see "t = " + t + nl 71.7 BreakPoint The next example demonstrates the Trace library usage to stop at a breakpoint! test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 71.8 Disable BreakPoints The next example demonstrates the Trace library usage and how to disable the Breakpoints! NoBreakPoints() test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 71.9 Using the Interactive Debugger The next example uses a Breakpoint to open the Interactive Debugger! load "tracelib.ring" test1() func test1 x = 10 see :test1 + nl t = 12 71.7. BreakPoint 815
  • 5. Ring Documentation, Release 1.7 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl Screen Shots: We have the Interactive Debugger at the Breakpoint! We can print the variables values We can change the variables values then continue execution 71.9. Using the Interactive Debugger 816
  • 6. Ring Documentation, Release 1.7 We can run the Interactive Debugger in the Output Window 71.9. Using the Interactive Debugger 817
  • 7. CHAPTER SEVENTYTWO EMBEDDING RING IN RING In this chapter we will learn about embedding Ring in Ring programs and applications. 72.1 Embedding Ring in Ring without sharing the State From Ring 1.0 we already have functions for embedding Ring in the C language. Also we can execute Ring code inside Ring programs using the eval() function. In this release we provide functions for embedding Ring in Ring programs without sharing the state. Advantages: 1. Quick integration for Ring programs and applications together without conflicts. 2. Execute and run Ring code in safe environments that we can trace. Example: pState = ring_state_init() ring_state_runcode(pState,"See 'Hello, World!'+nl") ring_state_runcode(pState,"x = 10") pState2 = ring_state_init() ring_state_runcode(pState2,"See 'Hello, World!'+nl") ring_state_runcode(pState2,"x = 20") ring_state_runcode(pState,"see x +nl") ring_state_runcode(pState2,"see x +nl") v1 = ring_state_findvar(pState,"x") v2 = ring_state_findvar(pState2,"x") see v1[3] + nl see V2[3] + nl ring_state_delete(pState) ring_state_delete(pState2) Output: Hello, World! Hello, World! 10 20 10 20 818
  • 8. Ring Documentation, Release 1.7 72.2 Serial Execution of Programs We can execute application after another application using ring_state_main() Example: chdir(exefolder()+"/../applications/formdesigner") ring_state_main('formdesigner.ring') chdir(exefolder()+"/../applications/cards") ring_state_main('cards.ring') 72.3 ring_state_setvar() Using ring_state_setvar() we can set variables value The value could be (String, Number, List or C Pointer) We need this function to quickly pass lists and C pointers to the Sub Ring Environment Syntax: ring_state_setvar(oState,cVariableName,Value) Example: load "guilib.ring" myapp = null win = null func main myapp = new qApp { win = new qWidget() { setWindowTitle("Advanced Example on using ring_state_setvar()") move(100,100) resize(600,400) new qPushButton(win) { setText("Test") setClickEvent("Test()") } # We need this because using load 'guilib.ring' in the sub environment # Will create timers by Qt and closing the window will not be enough # To close the application oFilter = new qAllEvents(win) oFilter.setCloseEvent("myapp.quit()") win.installeventfilter(oFilter) show() } exec() } func test pState = ring_state_init() ring_state_runcode(pstate,"load 'guilib.ring'") ring_state_runcode(pState,"x = NULL") # Pass String ring_state_setvar(pState,"x","hello") 72.2. Serial Execution of Programs 819
  • 9. Ring Documentation, Release 1.7 ring_state_runcode(pState,"? x") # Pass Number ring_state_setvar(pState,"x",100) ring_state_runcode(pState,"? x") # Pass List ring_state_setvar(pState,"x",["one","two","three"]) ring_state_runcode(pState,"? x") # Pass Object # We can't pass the Ring Object (win) # Because Objects store pointers to the Class Information # And the class is related to the Parent Ring Environment # And the sub Ring environment can't access it # But we can pass C pointers like win.pObject ring_state_setvar(pState,"x",win.pObject) # Now we create the object again but using the same C pointer # So we have access to the Same window in the parent Ring enviroment ring_state_runcode(pState," new qWidget { pObject = x setwindowtitle('Message from the Sub Ring Environment') } ") ring_state_delete(pState) 72.4 ring_state_new() and ring_state_mainfile() Using ring_state_new() and ring_state_mainfile() we can run Ring programs from Ring programs But unlike ring_state_main(), Here we can control when to delete the Ring state! This is important when we run GUI programs from GUI programs Because they will share the GUI Library (RingQt), And In this case the caller will call qApp.Exec() So the sub program, will not stop and will return to the Main program Here deleting the State of the sub programs will lead to a problem when we run the sub program events So keeping the state is important for sub GUI programs hosted in GUI programs. Example: load "guilib.ring" func main new qApp { win = new qWidget() { setWindowTitle("Test ring_state_mainfile()") resize(400,400) move(100,100) btn = new qPushButton(Win) { settext("test") setclickevent("mytest()") } show() } exec() } 72.4. ring_state_new() and ring_state_mainfile() 820
  • 10. Ring Documentation, Release 1.7 func mytest pState = ring_state_new() ring_state_mainfile(pState,"runprogram.ring") # Here we don't delete the state if we will run GUI application # So we can run the GUI application events // ring_state_delete(pState) If you will use this feature, remember to update the previous example based on your application needs So you can call ring_state_delete() at some point to avoid the memory leak! 72.4. ring_state_new() and ring_state_mainfile() 821