-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit1.dfm
572 lines (564 loc) · 16.8 KB
/
Unit1.dfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
object Form1: TForm1
Left = 236
Top = 214
Caption = 'RTC Scripting Engine Tester'
ClientHeight = 557
ClientWidth = 967
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 120
TextHeight = 16
object Splitter1: TSplitter
Left = 474
Top = 0
Width = 4
Height = 557
ResizeStyle = rsUpdate
ExplicitHeight = 551
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 474
Height = 557
Align = alLeft
Caption = 'Panel1'
TabOrder = 0
DesignSize = (
474
557)
object Label1: TLabel
Left = 10
Top = 12
Width = 371
Height = 16
Caption =
'Script code to compile and execute ... (script always in <? ... ' +
'?> )'
end
object Memo1: TMemo
Left = 7
Top = 36
Width = 459
Height = 505
Anchors = [akLeft, akTop, akRight, akBottom]
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Courier New'
Font.Style = []
Lines.Strings = (
'1. Claudia Schiffer example:'
'<h1>'
'<?'
'$Name := '#39'Schiffer'#39';'
'// do something here'
'if $Name = '#39'Schiffer'#39' then'
' '#39'Claudia'#39
' else'
' $Name;'
'?>'
'</h1>'
'------------'
'1b. Claudia Schiffer example using a code block:'
'<h1>'
'<?'
'$Vorname := code '
' if $Name = '#39'Schiffer'#39' then'
' '#39'Claudia'#39
' else'
' '#39'unknown'#39';'
''
'$Name := '#39'Schiffer'#39';'
'$Vorname " " $Name ?>'
'<? $Name := '#39'Becker'#39';'
''
'// See how the $Vorname variable changes ...'
'$Vorname " " $Name ?>'
'</h1>'
'--------------------------'
'2. Claudia Shiffer sample:'
'<?'
'function $GetVorname'
'begin'
' if $Name = '#39'Schiffer'#39' then'
' $result := '#39'Claudia'#39
' else'
' $result := '#39'unknown'#39';'
'end;'
'?>'
'<h1><? $GetVorname( Name:'#39'Schiffer'#39') ?></h1>'
''
'--------------------------'
'3. Claudia Shiffer sample:'
'<?'
'function $GetVorname $result :='
' if $Name = '#39'Schiffer'#39' then'
' '#39'Claudia'#39
' else'
' '#39'unknown'#39';'
'?>'
'<h1><? $GetVorname( Name:'#39'Schiffer'#39') ?></h1>'
''
'---------------------------'
'4. Claudia Schiffer sample:'
'<?'
'function $GetVorname $result :='
' if $Params.0 = '#39'Schiffer'#39' then'
' '#39'Claudia'#39
' else'
' '#39'unknown'#39';'
'?>'
'<h1><? // this last function is NOT expecting names'
' $GetVorname('#39'Schiffer'#39') ?></h1>'
''
'--------------------------------'
'5. Min and Max example without parameter names:'
'<?'
'function $max $result := '
' if $params.0 > $params.1 then $params.0'
' else $params.1;'
''
'function $min $result := '
' if $params.0 < $params.1 then $params.0'
' else $params.1;'
''
'$max(10,20);" - ";'
'$max(1, $max(3,5));'#39' - '#39';'
'$min(10,20);" ! "'
'?>'
''
'----------------------------------'
'6. Several different Min/Max examples'
'<?'
'function $max $result :='
'begin'
' if $PARAMS <> null then'
' { if $params.0 > $params.1 then $params.0 '
' else $params.1 }'
' else'
' { if $A > $B then $A '
' else $B }'
'end;'
''
'function $min $result :='
'begin'
' if $PARAMS <> null then'
' { if $params.0 < $params.1 then $params.0 '
' else $params.1 }'
' else'
' { if $A < $B then $A '
' else $B }'
'end;'
''
'?>Using "max" with parameter names: <? $max(a:10, b:20) ?>'
'Using "max" with index and "min" with names: <? $max(1, $min(b:3' +
', a:5))?>'
'Using "min with index: <? $min(10,20) ?>'
''
'------------------'
'7. Accessing fields in records'
'<?'
'// Defining a new local function "$fn"'
'function $fn $result := (x:10, y:20);'
'?>'
'Calling local function "$fn" '
'and working with the result (record).'
'<?'
'$x := $fn;'
'$x.count,'#39' - '#39', $x.x, '#39' - '#39', $x.y; '#39' / '#39';'
''
'// You can even override a function'
'function $fn $result := (30, 40);'
'?>'
'From this point on, we will be calling the new function'
'<?'
'$x := $fn;'
'$x.count,'#39' - '#39', $x.0, '#39' - '#39', $x.1; '#39' / '#39
'?>'
'You can also assign arrays directly to variables'
'<? $x := (50, 60,70,80,90,100);'
' (* Now that we got a few more elements,'
' Let'#39's write all elements out using a "for" loop ... *)'
''
'for $i := 0 to $x.count-1 do'
'// since this is a single command, we don'#39't need "begin/end"'
' $x($i) + if $i<$x.count-1 then '#39', '#39';'
'?>'
''
'----------------------------'
'8. Using $Result to caculate the output'
'<? function $test if $params <> nil then'
'begin'
' $result := 0;'
' for $i := 1 to $params.0 do $result += $i;'
'end;?>'
'Sum of the first 1000 integer numbers is <?$test(1000)?>'
''
'---------------------------'
'9. Sending parameters as an array '
' and enumerating through the array'
'<? function $sum if $params <>nil then'
' for $i := 0 to $params.count-1 do'
' $result += $params($i);'
''
'$sum(8,12,36,69,12);" = ";8+12+36+69+12'
'?>'
''
'--------------------------------------'
'10. Another array enumeration example:'
'<? function $test'
' begin'
' if $params <> nil then'
' for $k := 0 to $params.count-1 do'
' for $i := 1 to $params($k) do $result += $i;'
' end;'
''
'$test(300,100,10,1) "=" '
'$test(300)+$test(100)+$test(10)+$test(1) ?>'
''
'-------------------------'
'11. Simple calculations:'
'<? -12+10*10; " = "; (-12)+(10*10); " = "; 10*10-12 ?>'
'<? $x := (a:(10,20),b:(30,40));'
'$x.a.0*$x.a.1+$x.b.0*$x.b.1 " = " 10*20+30*40 " = "'
'$('#39'x'#39').a(0) * $x('#39'a'#39').1 + $x('#39'b.0'#39') * $x.b(1) ?>'
''
'-------------------------------------'
'12. Using FOR and "#" to generate a string of special chars:'
'<? for $i:= 32 to 64 do #$i ?>'
''
'-------------------'
'13. Testing recursive calls'
'<? function $test $result := if $params.0 >0 then'
#9'$params.0+$test($params.0-1);'
''
'(* Do not overdo it, or you will generate a Stack Overflow,'
' which will make the application crash (no warning).'
''
' Since the function call Stack is quite limited,'
' you should avoid recursive calls wherever possible, '
' especially since 99% implementations using recursive '
' calls can be implemented using loops and variables. *)'
''
'// Here is the same function without recursive calls ...'
'function $test2'
' begin'
' $result:= 0.0;'
' for $i := 0 to $params.0 do'
' $result += $i;'
' end;'
''
'// Both functions should return the same result'
'$test(123) " = " $test2(123) ?>'
''
'------------------'
'14. Testing calls to RTC Functions (written in Delphi)'
'<?'
'function $RandomList'
' begin'
' $Result := '#39#39'; '
' for $i := 1 to $cnt do'
' begin'
' $x := random($max);'
' if $Result<>'#39#39' then'
' $Result += '#39','#39'+$x'
' else'
' $Result := $x;'
' end;'
' end;'
'?>Here are our 10 random numbers (0-99):'
'<? $RandomList(cnt:10, max:100) ?>'
'RTC Function Time rerturns <? time ?>, '
'RTC Function Date says <? date ?> and'
'RTC Function Now shows <? Now ?>.'
''
'And here is a single random number:'
'<? random(100)+random(100) ?>'
''
'15. Test using DataSets in script'
'------------------------'
'<? '
'$x := new dataset;'
''
'for $i := 1 to 30 do'
' begin'
' $x.append;'
' for $j := 1 to 15 do'
' $x('#39'f'#39'+$j) := $i*$j;'
' end;'
'?>'
'"While" loop using First, Next, EOF:'
'<?'
'$x.first;'
'while not $x.eof do'
' begin'
' '#39'Row '#39' $x.row '#39') '#39
' for $i:=0 to $x.fieldcount-1 do'
' begin'
' $x($i);'
' if $i<$x.fieldcount-1 then '#39', '#39';'
' end;?>'
'<?$x.next;'
' end;?>'
'"For" loop using RowCount and Row and a codeblock for indirect a' +
'ccess:'
'<?'
'// now $rec points to $x'
'$rec := code $x;'
''
'for $i := 0 to $rec.rowcount-1 do'
' begin'
' $rec.row := $i;'
' '#39'Row '#39' $rec.row '#39') '#39
' for $i:=0 to $rec.fieldcount-1 do'
' begin'
' $rec($i);'
' if $i<$rec.fieldcount-1 then '#39', '#39';'
' end;?>'
'<?end;?>'
'Here is the same DataSet using RTC output:'
'<? $x ?>'
'And the same when using the $rec "pointer":'
'<? $rec ?>'
''
'16. Test writing and calling a script function'
'-----------------'
'<? function $PolyArea'
'begin'
' (* Return the area of a polygon with N vertices, where'
' the input consists of coordinates passed as records (X,Y) *)'
''
' if $params<>null then'
' begin'
' $Result := 0.0;'
' For $I := 0 to $params.count-1 do'
' begin'
' $cord1 := $params($I);'
' if $I<$params.count-1 then'
' $cord2 := $params($I+1)'
' else'
' $cord2 := $params(0);'
' $Result += $cord1.x * $cord2.y - $cord2.x * $cord1.y;'
' end;'
' if $Result < 0 then $Result := -$Result;'
''
' $Result /= 2.0;'
' end;'
'end;'
''
'$PolyArea( (x:0,y:0), (x:10,y:0), (x:10, y:10) ); ?>'
''
'17. The same script function working with polymorphic parameters' +
':'
'---------------------'
'<? '
'function $PolyArea'
'begin'
' (* Return the area of a polygon with N vertices, where'
' the input consists of coordinates passed as records (X,Y) *)'
''
' function $GetN $result :='
' if $params.0($params.1) <> NULL then $params.0($params.1)'
' else $params.0($params.2);'
''
' if $params<>null then'
' begin'
' $Result := 0.0;'
' For $I := 0 to $params.count-1 do'
' begin'
''
' $cord1 := $params($I);'
' if $I<$params.count-1 then'
' $cord2 := $params($I+1)'
' else'
' $cord2 := $params(0);'
' $Result += $GetN($cord1,0,'#39'x'#39') * $GetN($cord2,1,'#39'y'#39')'
' - $GetN($cord2,0,'#39'x'#39') * $GetN($cord1,1,'#39'y'#39');'
' end;'
' if $Result < 0 then $Result := -$Result;'
''
' $Result /= 2.0;'
' end;'
'end; '
''
'PolyArea((0,0), (10,0), (10,10)), '#39' = '#39','
'PolyArea((x:0,y:0), (x:10,y:0), (x:10,y:10)), '#39' = '#39','
'PolyArea((0,0), (x:10,y:0), (10,10)) ?>'
''
'18. The same script function using codeblocks:'
'---------------------'
'<? '
'function $PolyArea'
'begin'
' (* Return the area of a polygon with N vertices, where'
' the input consists of coordinates passed as records (X,Y) *)'
''
' (* We can declare our helper function $GetN inside the function' +
', so it '
' is invisible from outside andexists only inside this functio' +
'n. *)'
''
' function $GetN $result :='
' if $params.0($params.1) <> NULL then'
' $params.0($params.1)'
' else '
' $params.0($params.2);'
''
' if $params<>null then'
' begin'
' $Result := 0.0;'
''
' (* we can declare our code block $next here,'
' even before all variables used in code block were defined' +
'.'
' We will use this codeblock as "next index pointer". *)'
''
' $next := code'
' if $I<$params.count-1 then $I+1 else 0;'
''
' For $I := 0 to $params.count-1 do'
' begin'
''
' (* using code blocks also avoids making copies of the orig' +
'inal structure and allows'
' midifying the original structure through the "pointer" ' +
'variable, if necessary. *)'
' '
' $cord1 := code $params($I);'
' $cord2 := code $params($next);'
''
' $Result += $GetN($cord1,0,'#39'x'#39') * $GetN($cord2,1,'#39'y'#39')'
' - $GetN($cord2,0,'#39'x'#39') * $GetN($cord1,1,'#39'y'#39');'
' end;'
''
' if $Result < 0 then $Result := -$Result;'
''
' $Result /= 2.0;'
' end;'
'end; '
''
'?>This triangle is 50% of a 10 x 10 square:'
'<?PolyArea((0,0), (10,0), (10,10)), '#39' = '#39','
'PolyArea((x:0,y:0), (x:10,y:0), (x:10,y:10)), '#39' = '#39','
'PolyArea((0,0), (x:10,y:0), (10,10)) ?>')
ParentFont = False
ScrollBars = ssBoth
TabOrder = 0
WantTabs = True
WordWrap = False
end
object Button2: TButton
Left = 393
Top = 5
Width = 75
Height = 25
Caption = 'Button2'
TabOrder = 1
OnClick = Button2Click
end
end
object Panel2: TPanel
Left = 478
Top = 0
Width = 489
Height = 557
Align = alClient
TabOrder = 1
DesignSize = (
489
557)
object lblTime: TLabel
Left = 153
Top = 12
Width = 46
Height = 16
Caption = 'Time: ...'
end
object Button1: TButton
Left = 12
Top = 6
Width = 132
Height = 31
Caption = 'Execute Script (left)'
TabOrder = 0
OnClick = Button1Click
end
object Memo2: TMemo
Left = 8
Top = 40
Width = 473
Height = 505
Anchors = [akLeft, akTop, akRight, akBottom]
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Courier New'
Font.Style = []
ParentFont = False
ReadOnly = True
ScrollBars = ssBoth
TabOrder = 1
end
end
object RtcScriptEngine1: TRtcScriptEngine
FunctionGroup = FunctionGroup
ScriptOpen = '<?'
ScriptClose = '?>'
MaxCodeDepth = 500
MaxRecursion = 200
MaxLoopCount = 100000
Left = 432
Top = 47
end
object FunctionGroup: TRtcFunctionGroup
Left = 436
Top = 98
end
object FnTime: TRtcFunction
Group = FunctionGroup
FunctionName = 'Time'
OnExecute = FnTimeExecute
Left = 440
Top = 148
end
object FnDate: TRtcFunction
Group = FunctionGroup
FunctionName = 'Date'
OnExecute = FnDateExecute
Left = 492
Top = 148
end
object FnNow: TRtcFunction
Group = FunctionGroup
FunctionName = 'Now'
OnExecute = FnNowExecute
Left = 516
Top = 60
end
object FnRandom: TRtcFunction
Group = FunctionGroup
FunctionName = 'Random'
OnExecute = FnRandomExecute
Left = 520
Top = 190
end
object FnPolyArea: TRtcFunction
Group = FunctionGroup
FunctionName = 'PolyArea'
OnExecute = FnPolyAreaExecute
Left = 452
Top = 190
end
object DummyConnection: TRtcHttpServer
Left = 584
Top = 96
end
end