Skip to content

Commit e5f4728

Browse files
committed
fbdoc: update examples/manual from wiki
1 parent 2383e26 commit e5f4728

File tree

4 files changed

+148
-4
lines changed

4 files changed

+148
-4
lines changed

examples/manual/check/KeyPgDim_2.bas

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
'$lang: "qb"
1212

13-
'' All variables beginning with A through N default to the INTEGER data type
14-
'' All other variables will default to the SINGLE data type
13+
'' All variables beginning with A through N will default to the INTEGER data type
14+
'' All other variables default to the SINGLE data type
1515
DefInt I-N
1616

17+
Dim I, J, X, Y, T$, D As Double
1718
'' I and J are INTEGERs
1819
'' X and Y are SINGLEs
1920
'' T$ is STRING
2021
'' D is DOUBLE
21-
22-
Dim I, J, X, Y, T$, D As Double
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'' examples/manual/operator/let-list2.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOpLetlist
7+
'' --------
8+
9+
Type Parent
10+
Dim As Integer p1, p2
11+
End Type
12+
13+
Type Child Extends Parent
14+
Dim As Integer c1, c2
15+
End Type
16+
17+
Type GrandChild Extends Child
18+
Dim As Integer gc1, gc2
19+
End Type
20+
21+
Dim As GrandChild gc = Type(1, 2, 3, 4, 5, 6)
22+
23+
Dim As Integer i1, i2
24+
Dim As Integer j1, j2
25+
Dim As Parent p
26+
Dim As Child c
27+
28+
Let(c, i1, i2) = gc
29+
Print c.p1, c.p2, c.c1, c.c2, i1, i2
30+
31+
Let(p, j1, j2) = gc
32+
Print p.p1, p.p2, j1, j2
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'' examples/manual/udt/extendszstring1.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgExtendsZstring
7+
'' --------
8+
9+
Type myZstring Extends ZString
10+
Public:
11+
Declare Constructor (ByRef z As Const ZString = "")
12+
Declare Operator Cast () ByRef As Const ZString
13+
Declare Operator Let (ByRef z As Const ZString)
14+
Private:
15+
Dim As String s
16+
End Type
17+
18+
Constructor myZstring (ByRef z As Const ZString = "")
19+
This.s = z
20+
End Constructor
21+
22+
Operator myZstring.Cast () ByRef As Const ZString
23+
Return *StrPtr(This.s)
24+
End Operator
25+
26+
Operator myZstring.Let (ByRef z As Const ZString)
27+
This.s = z
28+
End Operator
29+
30+
Dim As myZstring z = "FreeBASIC"
31+
Print "'" & z & "'"
32+
33+
z &= " compiler"
34+
Print "'" & z & "'"
35+
36+
Sleep
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'' examples/manual/udt/extendszstring2.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgExtendsZstring
7+
'' --------
8+
9+
Type vZstring Extends ZString
10+
Public:
11+
Declare Constructor (ByVal pz As Const ZString Ptr = 0)
12+
Declare Operator Cast () ByRef As ZString
13+
Declare Operator Let (ByVal pz As Const ZString Ptr)
14+
Declare Operator [] (ByVal index As Integer) ByRef As UByte
15+
Declare Destructor ()
16+
Private:
17+
Dim As ZString Ptr p
18+
Dim As UInteger l
19+
End Type
20+
21+
Constructor vZstring (ByVal pz As Const ZString Ptr = 0)
22+
This.l = Len(*pz)
23+
This.p = CAllocate(This.l + 1, SizeOf(ZString))
24+
*This.p = *pz
25+
End Constructor
26+
27+
Operator vZstring.Cast () ByRef As ZString
28+
Return *This.p
29+
End Operator
30+
31+
Operator vZstring.Let (ByVal pz As Const ZString Ptr)
32+
If This.l < Len(*pz) Then
33+
Deallocate(This.p)
34+
This.l = Len(*pz)
35+
This.p = CAllocate(This.l + 1, SizeOf(ZString))
36+
End If
37+
*This.p = *pz
38+
End Operator
39+
40+
Operator vZstring.[] (ByVal index As Integer) ByRef As UByte
41+
Return This.p[index]
42+
End Operator
43+
44+
Destructor vZstring ()
45+
Deallocate(This.p)
46+
End Destructor
47+
48+
Operator Len (ByRef v As vZstring) As Integer
49+
Return Len(Type<String>(v)) '' found nothing better than this ('vZstring.l' being private)
50+
End Operator
51+
52+
Dim As vZstring v = "FreeBASIC"
53+
Print "'" & v & "'", Len(v)
54+
55+
Dim As ZString * 256 z
56+
z = *StrPtr(v) '' 'error 24: Invalid data types' without 'Extends Zstring'
57+
Print "'" & z & "'", Len(z)
58+
59+
v &= Space(2)
60+
Print "'" & v & "'", Len(v)
61+
RSet v, "FreeBASIC" '' 'error 24: Invalid data types' without 'Extends Zstring'
62+
Print "'" & v & "'", Len(v) '' ('Cast' must return a modifiable reference)
63+
64+
Select Case v '' 'error 24: Invalid data types' without 'Extends Zstring'
65+
Case Type<vZstring>(Trim(v) & " ")
66+
Print "Left justified"
67+
Case Type<vZstring>(" " & Trim(v))
68+
Print "Right justified"
69+
End Select
70+
71+
v[0] = Asc("-")
72+
Print "'" & v & "'", Len(v)
73+
74+
'Print "'" & Right(v, 5) & "'" '' 'Right' does not yet support types with 'Extends Zstring'
75+
Print "'" & Right(Str(v), 5) & "'" '' workaround
76+
77+
Sleep

0 commit comments

Comments
 (0)