OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / target / whatisnew2.txt
1 .. index:: 
2         single: What is new in Ring 1.2?; Introduction
3
4 ========================
5 What is new in Ring 1.2?
6 ========================
7
8 In this chapter we will learn about the changes and new features in Ring 1.2 release.
9
10 .. index:: 
11         pair: What is new in Ring 1.2?; List of changes and new features
12
13 List of changes and new features
14 ================================
15
16 Ring 1.2  comes with many new features 
17
18 * New Functions
19 * Better Functions
20 * Better Ring Notepad
21 * Better RingQt
22 * Objects Library for RingQt
23 * RingLibCurl
24 * Better Call Command
25 * Using NULL instead of NULLPointer()
26 * Display Warnings Option
27 * Better Quality
28
29 .. index:: 
30         pair: What is new in Ring 1.2?; New Functions
31
32 New Functions
33 =============
34
35 * PtrCmp() Function is a new function that compare between C pointers like the GUI objects.
36 * PrevFileName() Function is added to return the previous active source file name.
37 * RingVM_CFunctionsList() Function is added to return a list of functions written in C.
38 * RingVM_FunctionsList() Function is added to return a list of functions written in Ring.
39 * RingVM_ClassesList() Function is added to return a list of Classes.
40 * RingVM_PackagesList() Function is added to return a list of Packages.
41 * RingVM_MemoryList() Function is added to return a list of Memory Scopes and Variables.
42 * RingVM_CallList() Function is added to return a list of the functions call list.
43 * RingVM_FilesList() Function is added to return a list of the Ring Files.
44
45 Example:
46
47 .. code-block:: ring
48
49         fp = fopen("ptrcmp.ring","r")
50         fp2 = fp
51         fp3 = fopen("ptrcmp.ring","r")
52
53         see ptrcmp(fp,fp2) + nl
54         see ptrcmp(fp,fp3) + nl
55
56         fclose(fp)
57         fclose(fp3)
58
59 Output:
60
61 .. code-block:: ring
62
63         1
64         0
65
66 Also we can compare between them using the '=' operator
67
68 Example:
69
70 .. code-block:: ring
71
72         fp = fopen("ptrcmp2.ring","r")
73         fp2 = fopen("ptrcmp2.ring","r")
74         fp3 = fp
75         see fp = fp2
76         see nl
77         see fp = fp3
78         fclose(fp)
79         fclose(fp2)
80
81 Output:
82
83 .. code-block:: ring
84
85         0
86         1
87
88
89 Example:
90
91 The next function in stdlib.ring uses the PrevFileName() to know if the file of the
92 caller function is the main source file of the program or not.
93
94 .. code-block:: ring
95
96         Func IsMainSourceFile
97                 if PrevFileName() = sysargv[2]
98                         return true
99                 ok
100                 return false
101
102 .. index:: 
103         pair: What is new in Ring 1.2?; Better Functions
104
105 Better Functions
106 ================
107
108 The find() function is updated to support searching in lists using C pointers like GUI
109 Objects.
110
111 The type() function is updated to display the C pointers types (like the GUI Object Class
112 Name).
113
114 .. index:: 
115         pair: What is new in Ring 1.2?; Better Ring Notepad
116
117 Better Ring Notepad
118 ===================
119
120 The Ring Notepad will save the current line number of opened files to be restored when
121 we switch between files.
122
123 Also Ring Notepad will ask the user to save the file if the file content is changed when 
124 the user switch between files.
125
126 .. index:: 
127         pair: What is new in Ring 1.2?; Better RingQt
128
129 Better RingQt
130 =============
131
132 RingQt classes are updated to include methods to get events (The code that will be executed
133 when an event is fired). This is necessary to enable/disable events for some time or to
134 get the events information.
135
136 For example the next code disable an event then call a method then enable the event again.
137
138 .. code-block:: ring
139
140         cEvent = oView.oListResult.getCurrentItemChangedEvent()
141         oView.oListResult.setCurrentItemChangedEvent("")
142         FindValueAction()       # Call Method while an event is disabled
143         oView.oListResult.setCurrentItemChangedEvent(cEvent)
144
145 Also the QAllEvents class is updated where we can set the output from the event function
146 to be true or false using a new method added to the class called setEventOutput.
147
148 .. code-block:: ring
149
150         Load "guilib.ring"
151
152         MyApp = New qApp {
153                         win = new qWidget() {
154                                         setwindowtitle("Hello World")
155                                         setGeometry(100,100,370,250)
156                                         lineedit1 = new qlineedit(win) {
157                                                 setGeometry(10,100,350,30)
158                                                 setinputmask("9999;_") 
159                                                 oFilter = new qallevents(lineedit1)
160                                                 oFilter.setfocusoutEvent("pMove()")
161                                                 installeventfilter(oFilter)
162                                         }
163                                         lineedit2 = new qlineedit(win) {
164                                                         setGeometry(10,150,350,30)
165                                         }
166                                         show()
167                         }
168                         exec()
169         }
170         
171         func pMove
172                    win.setWindowTitle("xxxx")
173                    oFilter.setEventOutput(False)
174
175 .. index:: 
176         pair: What is new in Ring 1.2?; Objects Library for RingQt
177
178 Objects Library for RingQt
179 ==========================
180
181 Ring 1.2 comes with the Objects library for RingQt applications. Instead of using global
182 variables for windows objects and connecting events to objects using the object name, the
183 Objects Library will manage the GUI objects and will provide a more natural API to quickly
184 create one or many windows from the same class and the library provide a way to quickly set methods
185 to be executed when an event is fired. Also the library provide a natural interface to
186 quickly use the parent or the caller windows from the child or sub windows.
187
188 The Objects Library is designed to be used with the MVC Design Pattern.
189
190 The Objects Library is merged in RingQt so you can use it directly when you use RingQt
191
192 Example :
193
194 .. code-block:: ring
195
196         load "guilib.ring"
197
198         new qApp {
199                 open_window( :MainWindowController )
200                 exec()
201         }
202
203         class MainWindowController from WindowsControllerParent
204                 oView = new MainWindowView
205                 func SubWindowAction
206                         Open_window( :SubWindowController )
207                         Last_Window().SetParentObject(self)
208
209         class MainWindowView from WindowsViewParent
210                 win = new qWidget() {
211                         SetWindowTitle("Main Window")
212                         btnSub = new qPushButton(win) {
213                                 setText("Sub Window")
214                                 setClickEvent( Method( :SubWindowAction ) )
215                         }
216                         resize(400,400)
217                 }
218
219         class SubWindowController from WindowsControllerParent
220                 oView = new SubWindowView
221                 func SetMainWindowTitleAction
222                         Parent().oView.win.SetWindowTitle("Message from the Sub Window")
223                         oView.win.SetWindowTitle("Click Event Done!")
224
225         class SubWindowView from WindowsViewParent
226                 win = new qWidget() {
227                         SetWindowTitle("Sub Window")
228                         btnMsg = new qPushButton(win) {
229                                 setText("Set Main Window Title")
230                                 setClickEvent( Method( :SetMainWindowTitleAction ) )
231                         }
232                         btnClose = new qPushButton(win) {
233                                 Move(200,0)
234                                 setText("Close")
235                                 setClickEvent( Method( :CloseAction ) )
236                         }
237                         resize(400,400)
238                 }
239
240 .. index:: 
241         pair: What is new in Ring 1.2?; RingLibCurl
242
243 RingLibCurl
244 ===========
245
246 The LibCurl library is used starting from Ring 1.0 for the Download() and SendEmail() 
247 functions implementation. In Ring 1.2 more functions are added to provide a powerful
248 library (RingLibCurl) around LibCurl.
249
250 Example:
251
252 .. code-block:: ring
253
254         load "libcurl.ring"
255
256         curl = curl_easy_init()
257
258         cPostThis = "page=4&Number1=4&Number2=5"
259         curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/ringapp/index.ring?page=3")
260         curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cPostThis)
261
262         curl_easy_perform(curl)
263
264         curl_easy_cleanup(curl)
265
266
267 .. index:: 
268         pair: What is new in Ring 1.2?; Better Call Command
269
270 Better Call Command
271 ===================
272
273 The Call command is updated to support calling functions from object attributes also (not
274 only variables).
275
276 For example the next code from the Stars Fighter Game
277
278 .. code-block:: ring
279
280         cFunc = oself.keypress
281         call cFunc(oGame,oSelf,Key_Space)
282
283 Can be written in one line
284
285 .. code-block:: ring
286
287         call oself.keypress(oGame,oSelf,Key_Space)
288
289
290 .. index:: 
291         pair: What is new in Ring 1.2?; Using NULL instead of NULLPointer()
292
293 Using NULL instead of NULLPointer()
294 ===================================
295
296 We can pass NULL to functions instead of using NULLPointer()
297
298 For example the next code from RingLibSDL
299
300 .. code-block:: ring
301
302         SDL_RenderCopy(SDL_ren,tex,NULLPointer(),rect)
303
304 Can be written as in the next line
305
306 .. code-block:: ring
307
308         SDL_RenderCopy(SDL_ren,tex,NULL,rect)
309
310 .. index:: 
311         pair: What is new in Ring 1.2?; Display Warnings Option
312
313 Display Warnings Option
314 =======================
315
316 In Ring 1.2 the Ring compiler is updated to include the Display Warnings option (-w)
317
318 Example:
319
320 .. code-block:: ring
321         
322         load "stdlib.ring"
323         load "stdlib.ring"
324
325 compiling the program using the Display Warnings option will display the file duplication
326 warning, While without that option the error will pass silent.
327
328 This is a warning (not an error) because in large projects you may use the same file
329 more than one time. For example it's common to start each file with the next code. where
330 the function IsMainSourceFile() is part from the stdlib.ring
331
332 .. code-block:: ring
333
334         load "stdlib.ring"
335         if IsMainSourceFile() 
336                 // Testing
337         ok 
338
339 .. index:: 
340         pair: What is new in Ring 1.2?; Better Quality
341
342 Better Quality
343 ==============
344
345 Ring 1.2 is more stable, We discovered and fixed more bugs during Ring usage everyday
346 in practical projects. Some functions are optimized to be faster like the SubStr() function.
347 Also the documentation is more better.