SlideShare a Scribd company logo
Ring Documentation, Release 1.8
setwindowtitle("First")
setgeometry(100,100,500,500)
new qpushbutton(win1) {
setgeometry(100,100,100,30)
settext("close")
setclickevent("app1.quit()")
}
new qpushbutton(win1) {
setgeometry(250,100,100,30)
settext("Second")
setclickevent("second()")
}
showmaximized()
}
exec()
}
func second
win2 = new qwidget() {
setwindowtitle("Second")
setgeometry(100,100,500,500)
setwindowflags(Qt_dialog)
show()
}
80.45 How to use SQLite using ODBC?
In Ring 1.1 and later versions we have native support for SQLite, so you don’t need to use it through ODBC.
Also we can access SQLite through RingQt.
The answer to your question
pODBC = odbc_init()
odbc_connect(pODBC,"DRIVER=SQLite3 ODBC Driver;Database=mydb.db;LongNames=0;"+
"Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
odbc_execute(pODBC,"create table 'tel' ('ID','NAME','PHONE');")
odbc_execute(pODBC,"insert into 'tel' values ('1','Mahmoud','123456');")
odbc_execute(pODBC,"insert into 'tel' values ('2','Ahmed','123456');")
odbc_execute(pODBC,"insert into 'tel' values ('3','Ibrahim','123456');")
odbc_execute(pODBC,"select * from tel") + nl
nMax = odbc_colcount(pODBC)
See "Columns Count : " + nMax + nl
while odbc_fetch(pODBC)
See nl
for x = 1 to nMax
see odbc_getdata(pODBC,x)
if x != nMax see " - " ok
next
end
odbc_disconnect(pODBC)
odbc_close(pODBC)
Output:
80.45. How to use SQLite using ODBC? 911
Ring Documentation, Release 1.8
Columns Count : 3
1 - Mahmoud - 123456
2 - Ahmed - 123456
3 - Ibrahim - 123456
The program will create the file : mydb.db
Note : when I print the odbc drivers I see the long list that includes
SQLite3 ODBC Driver - UsageCount=1
SQLite ODBC Driver - UsageCount=1
SQLite ODBC (UTF-8) Driver - UsageCount=1
And I’m using “SQLite3 ODBC Driver”.
80.46 Can I connect to dbase/harbour database?
You can connect to any database using ODBC
To connect to xbase files (*.DBF)
See "Using DBF Files using ODBC" + nl
pODBC = odbc_init()
See "Connect to database" + nl
odbc_connect(pODBC,"Driver={Microsoft dBase Driver (*.dbf)};"+
"datasource=dBase Files;DriverID=277")
See "Select data" + nl
odbc_execute(pODBC,"select * from tel.dbf")
nMax = odbc_colcount(pODBC)
See "Columns Count : " + nMax + nl
while odbc_fetch(pODBC)
See "Row data:" + nl
for x = 1 to nMax
see odbc_getdata(pODBC,x) + " - "
next
end
See "Close database..." + nl
odbc_disconnect(pODBC)
odbc_close(pODBC)
Output
Using DBF Files using ODBC
Connect to database
Select data
Columns Count : 3
Row data:
Ahmad - Egypt - 234567 - Row data:
Fady - Egypt - 345678 - Row data:
Shady - Egypt - 456789 - Row data:
Mahmoud - Egypt - 123456 - Close database...
Also you can connect to a Visual FoxPro database (requires installing Visual FoxPro driver)
See "ODBC test 6" + nl
pODBC = odbc_init()
See "Connect to database" + nl
80.46. Can I connect to dbase/harbour database? 912
Ring Documentation, Release 1.8
odbc_connect(pODBC,"Driver={Microsoft Visual FoxPro Driver};"+
"SourceType=DBC;SourceDB=C:PWCT19ssbuildPWCTDATACH1Datamydata.dbc;")
See "Select data" + nl
see odbc_execute(pODBC,"select * from t38") + nl
nMax = odbc_colcount(pODBC)
See "Columns Count : " + nMax + nl
while odbc_fetch(pODBC)
See "Row data:" + nl
for x = 1 to nMax
see odbc_getdata(pODBC,x) + " - "
next
end
See "Close database..." + nl
odbc_disconnect(pODBC)
odbc_close(pODBC)
80.47 Why setClickEvent() doesn’t see the object methods directly?
setClickEvent(cCode) take a string contains code. The code will be executed when the event happens.
Ring support Many Programming Paradigms like Procedural, OOP, Functional and others.
But when you support many paradigms at the language level you can’t know which paradigm will be used so you have
two options
1. Provide General Solutions that works with many programming paradigms.
2. Provide Many Specific solutions where each one match a specific paradigm.
setClickEvent() and others belong to (General Solutions that works with many programming paradigms).
You just pass a string of code that will be executed without any care about classes and objects.
This code could be anything like calling a function, calling a method and setting variable value.
Some other languages force you to use OOP and call methods for events. Also some other languages uses anonymous
functions that may get parameters like the current object.
Now we have the general solution (not restricted with any paradigm), In the future we may add specific solutions that
match specific paradigms (OOP, Functional, Declarative and Natural).
80.48 Why I get Calling Function without definition Error?
Each program follow the next order
1 - Loading Files 2 - Global Variables and Statements 3 - Functions 4 - Packages, Classes and Methods
So what does that mean ?
1. **** No Functions comes After Classes ****
2. **** No command is required to end functions/methods/classes/packages ****
Look at this example
See "Hello"
test()
func test
80.47. Why setClickEvent() doesn’t see the object methods directly? 913
Ring Documentation, Release 1.8
see "message from the test function!" + nl
class test
In the previous example we have a function called test() so we can call it directly using test()
In the next example, test() will become a method
See"Hello"
test() # runtime error message
class test
func test # Test() now is a method (not a function)
see "message from the test method!" + nl
The errors comes when you define a method then try calling it directly as a function.
The previous program must be
See"Hello"
new test { test() } # now will call the method
class test
func test # Test() now is a method (not a function)
see "message from the test method!" + nl
80.49 Can Ring work on Windows XP?
Ring can work on Windows XP and load extensions without problems.
Just be sure that the extension can work on Windows XP and your compiler version support that (modern compilers
requires some flags to support XP)
Check this topic https://blogs.msdn.microsoft.com/vcblog/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-
2012/
For example, We added
/link /SUBSYSTEM:CONSOLE,"5.01"
To the batch file to support Windows XP
See : https://github.com/ring-lang/ring/blob/master/src/buildvccomplete.bat
80.50 How to extend RingQt and add more classes?
You have many options
In general you can extend Ring using C or C++ code
Ring from Ring code you can call C Functions or use C++ Classes & Methods
This chapter in the documentation explains this part in the language http://ring-
lang.sourceforge.net/doc/extension.html
For example the next code in .c file can be compiled to a DLL file using the Ring library (.lib)
#include "ring.h"
RING_FUNC(ring_ringlib_dlfunc)
{
80.49. Can Ring work on Windows XP? 914
Ring Documentation, Release 1.8
printf("Message from dlfunc");
}
RING_API void ringlib_init(RingState *pRingState)
{
ring_vm_funcregister("dlfunc",ring_ringlib_dlfunc);
}
Then from Ring you can load the DLL file using LoadLib() function then call the C function that called dlfunc() as
any Ring function.
See "Dynamic DLL" + NL
LoadLib("ringlib.dll")
dlfunc()
Output
Dynamic DLL
Message from dlfunc
When you read the documentation you will know about how to get parameters like (strings, numbers, lists and objects)
And how to return a value (any type) from you function.
From experience, when we support a C library or C++ Library
We discovered that a lot of functions share a lot of code
To save our time, and to quickly generate wrappers for C/C++ Libraries to be used in Ring
We have this code generator
https://github.com/ring-lang/ring/blob/master/extensions/codegen/parsec.ring
The code generator is just a Ring program < 1200 lines of Ring code
The generator take as input a configuration file contains the C/C++ library information
like Functions Prototype, Classes and Methods, Constants, Enum, Structures and members , etc.
Then the generator will generate
*.C File for C libraries (to be able to use the library functions)
*.CPP File for C++ libraries (to be able to use C++ classes and methods)
*.Ring File (to be able to use C++ classes as Ring classes)
*.RH file (Constants)
To understand how the generator work check this extension for the Allegro game programming library
https://github.com/ring-lang/ring/tree/master/extensions/ringallegro
At first we have the configuration file
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/allegro.cf
To write this file, i just used the Allegro documentation + the Ring code generator rules
Then after executing the generator using this batch file
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/gencode.bat
or using this script
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/gencode.sh
80.50. How to extend RingQt and add more classes? 915
Ring Documentation, Release 1.8
I get the generated source code file
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/ring_allegro.c
The generated source code file (ring_allegro.c) is around 12,000 Lines of code (12 KLOC)
While the configuration file is less than 1 KLOC
To build the library (create the DLL files)
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/buildvc.bat
Also you can check this extension for the LibSDL Library
https://github.com/ring-lang/ring/tree/master/extensions/ringsdl
After this know you should know about
1 - Writing the configuration file
2 - Using the Code Generator
3 - Building your library/extension
4 - Using your library/extension from Ring code
Let us move now to you question about Qt
We have RingQt which is just an extension to ring (ringqt.dll)
You don’t need to modify Ring.
1. You just need to modify RingQt
2. Or extend Ring with another extension based on Qt (but the same Qt version)
For the first option see the RingQt extension
https://github.com/ring-lang/ring/tree/master/extensions/ringqt
Configuration file
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/qt.cf
To generate the source code
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.bat
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.sh
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencodeandroid.bat
To build the DLL/so/Dylib files
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildmingw32.bat
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildgcc.sh
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildclang.sh
Study RingQt
Learn about the options that you have
1. wrapping a Qt class directly
2. Creating a new class then wrapping your new class
80.50. How to extend RingQt and add more classes? 916
Ring Documentation, Release 1.8
For the second option (in the previous two points or in the two points before that)
You will create new classes in C++ code
Then you merge these classes to RingQt or provide special DLL for them (your decision)
If your work is general (will help others) just put it to RingQt.
if your work is special (to specific application) just put it in another extension.
80.51 How to add Combobox and other elements to the cells of a
QTableWidget?
Check the next code
Load "guilib.ring"
New qApp
{
win1 = new qMainWindow() {
setGeometry(100,100,1100,370)
setwindowtitle("Using QTableWidget")
Table1 = new qTableWidget(win1) {
setrowcount(10) setcolumncount(10)
setGeometry(0,0,800,400)
setselectionbehavior(QAbstractItemView_SelectRows)
for x = 1 to 10
for y = 1 to 10
item1 = new qtablewidgetitem("R"+X+"C"+Y)
setitem(x-1,y-1, item1)
next
next
cmb = new QComboBox(Table1) {
alist = ["one","two","three","four","five"]
for x in aList additem(x,0) next
}
setCellWidget(5, 5, cmb)
}
setcentralwidget(table1)
show()
}
exec()
}
80.52 How to perform some manipulations on selected cells in
QTableWidget?
Check the next sample
Load "guilib.ring"
New qApp {
80.51. How to add Combobox and other elements to the cells of a QTableWidget? 917
Ring Documentation, Release 1.8
win1 = new qMainWindow() {
setGeometry(100,100,800,600)
setwindowtitle("Using QTableWidget")
Table1 = new qTableWidget(win1) {
setrowcount(10) setcolumncount(10)
setGeometry(10,10,400,400)
for x = 1 to 10
for y = 1 to 10
item1 = new qtablewidgetitem("10")
setitem(x-1,y-1,item1)
next
next
}
btn1 = new qPushButton(win1) {
setText("Increase")
setGeometry(510,10,100,30)
setClickEvent("pClick()")
}
show()
}
exec()
}
func pClick
for nRow = 0 to Table1.rowcount() - 1
for nCol = 0 to Table1.columncount() - 1
Table1.item(nRow,nCol) {
if isSelected()
setText( "" + ( 10 + text()) )
ok
}
next
next
80.53 Which of 3 coding styles are commonly used or recommended
by the community?
1. Just select any style of them but don’t mix between the different styles in the same project or at least in
the same context (Implementation, Tests, Scripts, etc)
Note: State the rules in the start of each project and follow it.
2. You can create your style (by changing keywords) - The idea is about customization and freedom.
Note: It’s better to change keywords and create new style only for a clear reason like using another natural language
(Arabic, French, etc.)
3. The First style is better (IMHO) for questions, tutorials and small applications/programs (Less than 5,000 LOC)
Example : Ring Book, Most of Ring Samples and Applications.
4. The Third style is better(IMHO) for large applications and mainstream programmers
Example (Form Designer) : https://github.com/ring-lang/ring/tree/master/applications/formdesigner
80.53. Which of 3 coding styles are commonly used or recommended by the community? 918
CHAPTER
EIGHTYONE
LANGUAGE REFERENCE
In this chapter we will learn about
• Language keywords
• Language Functions
• Compiler Errors
• Runtime Errors
• Environment Errors
• Language Grammar
• Virtual Machine (VM) Instructions
81.1 Language Keywords
Keywords Count : 49
• again
• and
• but
• bye
• call
• case
• catch
• changeringkeyword
• changeringoperator
• class
• def
• do
• done
• else
• elseif
• end
919
Ring Documentation, Release 1.8
• exit
• for
• from
• func
• get
• give
• if
• import
• in
• load
• loadsyntax
• loop
• new
• next
• not
• off
• ok
• on
• or
• other
• package
• private
• put
• return
• see
• step
• switch
• to
• try
• while
• endfunc
• endclass
• endpackage
81.1. Language Keywords 920

More Related Content

What's hot (20)

PPTX
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
 
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
PDF
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
PPTX
What’s new in C# 6
Fiyaz Hasan
 
PDF
Java 7 LavaJUG
julien.ponge
 
PDF
Dagger & rxjava & retrofit
Ted Liang
 
PDF
The Ring programming language version 1.7 book - Part 8 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 31 of 202
Mahmoud Samir Fayed
 
PPTX
Jersey framework
knight1128
 
PDF
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
PPTX
Jdk 7 4-forkjoin
knight1128
 
PDF
The Ring programming language version 1.5.3 book - Part 26 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4 book - Part 3 of 30
Mahmoud Samir Fayed
 
DOCX
srgoc
Gaurav Singh
 
PDF
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 
PDF
ikh331-06-distributed-programming
Anung Ariwibowo
 
PDF
Clang tidy
Yury Yafimachau
 
DOCX
Fia fabila
fiafabila
 
PDF
201913001 khairunnisa progres_harian
KhairunnisaPekanbaru
 
PDF
Tugas 2
Novi_Wahyuni
 
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
What’s new in C# 6
Fiyaz Hasan
 
Java 7 LavaJUG
julien.ponge
 
Dagger & rxjava & retrofit
Ted Liang
 
The Ring programming language version 1.7 book - Part 8 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 31 of 202
Mahmoud Samir Fayed
 
Jersey framework
knight1128
 
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
Jdk 7 4-forkjoin
knight1128
 
The Ring programming language version 1.5.3 book - Part 26 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 3 of 30
Mahmoud Samir Fayed
 
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 
ikh331-06-distributed-programming
Anung Ariwibowo
 
Clang tidy
Yury Yafimachau
 
Fia fabila
fiafabila
 
201913001 khairunnisa progres_harian
KhairunnisaPekanbaru
 
Tugas 2
Novi_Wahyuni
 

Similar to The Ring programming language version 1.8 book - Part 95 of 202 (20)

PDF
The Ring programming language version 1.10 book - Part 102 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 180 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 176 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 8 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 15 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 15 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 19 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 8 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 7 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 8 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 21 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 14 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 92 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 77 of 202
Mahmoud Samir Fayed
 
ODP
Developing Drizzle Replication Plugins
Padraig O'Sullivan
 
The Ring programming language version 1.10 book - Part 102 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 180 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 176 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 8 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 15 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 15 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 19 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 8 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 7 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 8 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 21 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 14 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 92 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 77 of 202
Mahmoud Samir Fayed
 
Developing Drizzle Replication Plugins
Padraig O'Sullivan
 
Ad

More from Mahmoud Samir Fayed (20)

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

Recently uploaded (20)

PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Import Data Form Excel to Tally Services
Tally xperts
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 

The Ring programming language version 1.8 book - Part 95 of 202

  • 1. Ring Documentation, Release 1.8 setwindowtitle("First") setgeometry(100,100,500,500) new qpushbutton(win1) { setgeometry(100,100,100,30) settext("close") setclickevent("app1.quit()") } new qpushbutton(win1) { setgeometry(250,100,100,30) settext("Second") setclickevent("second()") } showmaximized() } exec() } func second win2 = new qwidget() { setwindowtitle("Second") setgeometry(100,100,500,500) setwindowflags(Qt_dialog) show() } 80.45 How to use SQLite using ODBC? In Ring 1.1 and later versions we have native support for SQLite, so you don’t need to use it through ODBC. Also we can access SQLite through RingQt. The answer to your question pODBC = odbc_init() odbc_connect(pODBC,"DRIVER=SQLite3 ODBC Driver;Database=mydb.db;LongNames=0;"+ "Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;") odbc_execute(pODBC,"create table 'tel' ('ID','NAME','PHONE');") odbc_execute(pODBC,"insert into 'tel' values ('1','Mahmoud','123456');") odbc_execute(pODBC,"insert into 'tel' values ('2','Ahmed','123456');") odbc_execute(pODBC,"insert into 'tel' values ('3','Ibrahim','123456');") odbc_execute(pODBC,"select * from tel") + nl nMax = odbc_colcount(pODBC) See "Columns Count : " + nMax + nl while odbc_fetch(pODBC) See nl for x = 1 to nMax see odbc_getdata(pODBC,x) if x != nMax see " - " ok next end odbc_disconnect(pODBC) odbc_close(pODBC) Output: 80.45. How to use SQLite using ODBC? 911
  • 2. Ring Documentation, Release 1.8 Columns Count : 3 1 - Mahmoud - 123456 2 - Ahmed - 123456 3 - Ibrahim - 123456 The program will create the file : mydb.db Note : when I print the odbc drivers I see the long list that includes SQLite3 ODBC Driver - UsageCount=1 SQLite ODBC Driver - UsageCount=1 SQLite ODBC (UTF-8) Driver - UsageCount=1 And I’m using “SQLite3 ODBC Driver”. 80.46 Can I connect to dbase/harbour database? You can connect to any database using ODBC To connect to xbase files (*.DBF) See "Using DBF Files using ODBC" + nl pODBC = odbc_init() See "Connect to database" + nl odbc_connect(pODBC,"Driver={Microsoft dBase Driver (*.dbf)};"+ "datasource=dBase Files;DriverID=277") See "Select data" + nl odbc_execute(pODBC,"select * from tel.dbf") nMax = odbc_colcount(pODBC) See "Columns Count : " + nMax + nl while odbc_fetch(pODBC) See "Row data:" + nl for x = 1 to nMax see odbc_getdata(pODBC,x) + " - " next end See "Close database..." + nl odbc_disconnect(pODBC) odbc_close(pODBC) Output Using DBF Files using ODBC Connect to database Select data Columns Count : 3 Row data: Ahmad - Egypt - 234567 - Row data: Fady - Egypt - 345678 - Row data: Shady - Egypt - 456789 - Row data: Mahmoud - Egypt - 123456 - Close database... Also you can connect to a Visual FoxPro database (requires installing Visual FoxPro driver) See "ODBC test 6" + nl pODBC = odbc_init() See "Connect to database" + nl 80.46. Can I connect to dbase/harbour database? 912
  • 3. Ring Documentation, Release 1.8 odbc_connect(pODBC,"Driver={Microsoft Visual FoxPro Driver};"+ "SourceType=DBC;SourceDB=C:PWCT19ssbuildPWCTDATACH1Datamydata.dbc;") See "Select data" + nl see odbc_execute(pODBC,"select * from t38") + nl nMax = odbc_colcount(pODBC) See "Columns Count : " + nMax + nl while odbc_fetch(pODBC) See "Row data:" + nl for x = 1 to nMax see odbc_getdata(pODBC,x) + " - " next end See "Close database..." + nl odbc_disconnect(pODBC) odbc_close(pODBC) 80.47 Why setClickEvent() doesn’t see the object methods directly? setClickEvent(cCode) take a string contains code. The code will be executed when the event happens. Ring support Many Programming Paradigms like Procedural, OOP, Functional and others. But when you support many paradigms at the language level you can’t know which paradigm will be used so you have two options 1. Provide General Solutions that works with many programming paradigms. 2. Provide Many Specific solutions where each one match a specific paradigm. setClickEvent() and others belong to (General Solutions that works with many programming paradigms). You just pass a string of code that will be executed without any care about classes and objects. This code could be anything like calling a function, calling a method and setting variable value. Some other languages force you to use OOP and call methods for events. Also some other languages uses anonymous functions that may get parameters like the current object. Now we have the general solution (not restricted with any paradigm), In the future we may add specific solutions that match specific paradigms (OOP, Functional, Declarative and Natural). 80.48 Why I get Calling Function without definition Error? Each program follow the next order 1 - Loading Files 2 - Global Variables and Statements 3 - Functions 4 - Packages, Classes and Methods So what does that mean ? 1. **** No Functions comes After Classes **** 2. **** No command is required to end functions/methods/classes/packages **** Look at this example See "Hello" test() func test 80.47. Why setClickEvent() doesn’t see the object methods directly? 913
  • 4. Ring Documentation, Release 1.8 see "message from the test function!" + nl class test In the previous example we have a function called test() so we can call it directly using test() In the next example, test() will become a method See"Hello" test() # runtime error message class test func test # Test() now is a method (not a function) see "message from the test method!" + nl The errors comes when you define a method then try calling it directly as a function. The previous program must be See"Hello" new test { test() } # now will call the method class test func test # Test() now is a method (not a function) see "message from the test method!" + nl 80.49 Can Ring work on Windows XP? Ring can work on Windows XP and load extensions without problems. Just be sure that the extension can work on Windows XP and your compiler version support that (modern compilers requires some flags to support XP) Check this topic https://blogs.msdn.microsoft.com/vcblog/2012/10/08/windows-xp-targeting-with-c-in-visual-studio- 2012/ For example, We added /link /SUBSYSTEM:CONSOLE,"5.01" To the batch file to support Windows XP See : https://github.com/ring-lang/ring/blob/master/src/buildvccomplete.bat 80.50 How to extend RingQt and add more classes? You have many options In general you can extend Ring using C or C++ code Ring from Ring code you can call C Functions or use C++ Classes & Methods This chapter in the documentation explains this part in the language http://ring- lang.sourceforge.net/doc/extension.html For example the next code in .c file can be compiled to a DLL file using the Ring library (.lib) #include "ring.h" RING_FUNC(ring_ringlib_dlfunc) { 80.49. Can Ring work on Windows XP? 914
  • 5. Ring Documentation, Release 1.8 printf("Message from dlfunc"); } RING_API void ringlib_init(RingState *pRingState) { ring_vm_funcregister("dlfunc",ring_ringlib_dlfunc); } Then from Ring you can load the DLL file using LoadLib() function then call the C function that called dlfunc() as any Ring function. See "Dynamic DLL" + NL LoadLib("ringlib.dll") dlfunc() Output Dynamic DLL Message from dlfunc When you read the documentation you will know about how to get parameters like (strings, numbers, lists and objects) And how to return a value (any type) from you function. From experience, when we support a C library or C++ Library We discovered that a lot of functions share a lot of code To save our time, and to quickly generate wrappers for C/C++ Libraries to be used in Ring We have this code generator https://github.com/ring-lang/ring/blob/master/extensions/codegen/parsec.ring The code generator is just a Ring program < 1200 lines of Ring code The generator take as input a configuration file contains the C/C++ library information like Functions Prototype, Classes and Methods, Constants, Enum, Structures and members , etc. Then the generator will generate *.C File for C libraries (to be able to use the library functions) *.CPP File for C++ libraries (to be able to use C++ classes and methods) *.Ring File (to be able to use C++ classes as Ring classes) *.RH file (Constants) To understand how the generator work check this extension for the Allegro game programming library https://github.com/ring-lang/ring/tree/master/extensions/ringallegro At first we have the configuration file https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/allegro.cf To write this file, i just used the Allegro documentation + the Ring code generator rules Then after executing the generator using this batch file https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/gencode.bat or using this script https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/gencode.sh 80.50. How to extend RingQt and add more classes? 915
  • 6. Ring Documentation, Release 1.8 I get the generated source code file https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/ring_allegro.c The generated source code file (ring_allegro.c) is around 12,000 Lines of code (12 KLOC) While the configuration file is less than 1 KLOC To build the library (create the DLL files) https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/buildvc.bat Also you can check this extension for the LibSDL Library https://github.com/ring-lang/ring/tree/master/extensions/ringsdl After this know you should know about 1 - Writing the configuration file 2 - Using the Code Generator 3 - Building your library/extension 4 - Using your library/extension from Ring code Let us move now to you question about Qt We have RingQt which is just an extension to ring (ringqt.dll) You don’t need to modify Ring. 1. You just need to modify RingQt 2. Or extend Ring with another extension based on Qt (but the same Qt version) For the first option see the RingQt extension https://github.com/ring-lang/ring/tree/master/extensions/ringqt Configuration file https://github.com/ring-lang/ring/blob/master/extensions/ringqt/qt.cf To generate the source code https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.bat https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.sh https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencodeandroid.bat To build the DLL/so/Dylib files https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildmingw32.bat https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildgcc.sh https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildclang.sh Study RingQt Learn about the options that you have 1. wrapping a Qt class directly 2. Creating a new class then wrapping your new class 80.50. How to extend RingQt and add more classes? 916
  • 7. Ring Documentation, Release 1.8 For the second option (in the previous two points or in the two points before that) You will create new classes in C++ code Then you merge these classes to RingQt or provide special DLL for them (your decision) If your work is general (will help others) just put it to RingQt. if your work is special (to specific application) just put it in another extension. 80.51 How to add Combobox and other elements to the cells of a QTableWidget? Check the next code Load "guilib.ring" New qApp { win1 = new qMainWindow() { setGeometry(100,100,1100,370) setwindowtitle("Using QTableWidget") Table1 = new qTableWidget(win1) { setrowcount(10) setcolumncount(10) setGeometry(0,0,800,400) setselectionbehavior(QAbstractItemView_SelectRows) for x = 1 to 10 for y = 1 to 10 item1 = new qtablewidgetitem("R"+X+"C"+Y) setitem(x-1,y-1, item1) next next cmb = new QComboBox(Table1) { alist = ["one","two","three","four","five"] for x in aList additem(x,0) next } setCellWidget(5, 5, cmb) } setcentralwidget(table1) show() } exec() } 80.52 How to perform some manipulations on selected cells in QTableWidget? Check the next sample Load "guilib.ring" New qApp { 80.51. How to add Combobox and other elements to the cells of a QTableWidget? 917
  • 8. Ring Documentation, Release 1.8 win1 = new qMainWindow() { setGeometry(100,100,800,600) setwindowtitle("Using QTableWidget") Table1 = new qTableWidget(win1) { setrowcount(10) setcolumncount(10) setGeometry(10,10,400,400) for x = 1 to 10 for y = 1 to 10 item1 = new qtablewidgetitem("10") setitem(x-1,y-1,item1) next next } btn1 = new qPushButton(win1) { setText("Increase") setGeometry(510,10,100,30) setClickEvent("pClick()") } show() } exec() } func pClick for nRow = 0 to Table1.rowcount() - 1 for nCol = 0 to Table1.columncount() - 1 Table1.item(nRow,nCol) { if isSelected() setText( "" + ( 10 + text()) ) ok } next next 80.53 Which of 3 coding styles are commonly used or recommended by the community? 1. Just select any style of them but don’t mix between the different styles in the same project or at least in the same context (Implementation, Tests, Scripts, etc) Note: State the rules in the start of each project and follow it. 2. You can create your style (by changing keywords) - The idea is about customization and freedom. Note: It’s better to change keywords and create new style only for a clear reason like using another natural language (Arabic, French, etc.) 3. The First style is better (IMHO) for questions, tutorials and small applications/programs (Less than 5,000 LOC) Example : Ring Book, Most of Ring Samples and Applications. 4. The Third style is better(IMHO) for large applications and mainstream programmers Example (Form Designer) : https://github.com/ring-lang/ring/tree/master/applications/formdesigner 80.53. Which of 3 coding styles are commonly used or recommended by the community? 918
  • 9. CHAPTER EIGHTYONE LANGUAGE REFERENCE In this chapter we will learn about • Language keywords • Language Functions • Compiler Errors • Runtime Errors • Environment Errors • Language Grammar • Virtual Machine (VM) Instructions 81.1 Language Keywords Keywords Count : 49 • again • and • but • bye • call • case • catch • changeringkeyword • changeringoperator • class • def • do • done • else • elseif • end 919
  • 10. Ring Documentation, Release 1.8 • exit • for • from • func • get • give • if • import • in • load • loadsyntax • loop • new • next • not • off • ok • on • or • other • package • private • put • return • see • step • switch • to • try • while • endfunc • endclass • endpackage 81.1. Language Keywords 920