Κυριακή 27 Οκτωβρίου 2024

Revision 40, Version 12

 Fix for string arrays of type "arrays with square brackets":

string a[3]="ok12345"
? a[0]
? left$(a[0], 3)
? ucase$(a[0])
? a[0]+a[1]
? strrev$(a[1])
? len(a)=4, len(a[3])=7

Old revisions return fault values for left$(), Rigt$() and all these functions for strings.

These type of arrays may have second dimension (as a collection of arrays, each one may have different length). Also a string a[3] make 4 item from 0 to 3

string a[3][2]="ok12345"
? a[0][0]
? left$(a[0][0], 3)
? ucase$(a[0][0])
? a[0][0]+a[1][0]
? len(a)=4


a[5][10]="expand"
? a[5][10]
? len(a)=4, len(a[5])=11, len(a[5][10])=6


These type of arrays exist in M2000 to used for passing pointers when we call external function:

module testArr {
Declare PathAddBackslash Lib "Shlwapi.PathAddBackslashW" { long string_pointer}
Declare global GetMem4 lib "msvbvm60.GetMem4" {Long addr, Long retValue}

string a[2]="ok1234"
a[1] = "C:"+String$(Chr$(0), 250)
function ArrPtr(a, x) {
long ret
With a, "ArrPtr" as a.ArrPtr()
x=GetMem4(a.ArrPtr(0)+4*x, varptr(ret))
=ret
}
if len(a[1])=0 then exit
m= PathAddBackslash(Arrptr(a, 1))
Print LeftPart$(a[1],0)
}
testArr
module testArr {
Declare PathAddBackslash Lib "Shlwapi.PathAddBackslashW" { long string_pointer}
Declare global GetMem4 lib "msvbvm60.GetMem4" {Long addr, Long retValue}


string a[2][4]="ok1234"
a[2][4] = "C:"+String$(Chr$(0), 250)
function ArrPtr(a, n, x) {
long ret
With a, "ArrPtr" as a.ArrPtr()
x=GetMem4(a.ArrPtr(n)+4*x, varptr(ret))
=ret
}
if len(a[2][4])=0 then exit
m= PathAddBackslash(Arrptr(a, 2, 4))
Print LeftPart$(a[2][4],0)
}
testArr


Although this external function handled using a by reference string (we can pass by reference item of a string or an array, but not item of an array with square brackets) (do not pass the thispath$ by reference to PathAddBackslach, isn't a string, is an object with a read only value):

module testArr2 {
Declare PathAddBackslash Lib "Shlwapi.PathAddBackslashW" { &Path$ }
const thispath$="C:"+String$(Chr$(0), 250)

string a = thispath$
m = PathAddBackslash(&a)
Print LeftPart$(a, 0)

a$ = thispath$
m = PathAddBackslash(&a$)
Print LeftPart$(a$, 0)

dim a$(4)
a$(3) = thispath$
m = PathAddBackslash(&a$(3))
Print LeftPart$(a$(3), 0)

dim a(4)
a(3) = thispath$
m = PathAddBackslash(&a(3))
Print LeftPart$(a(3), 0)

dim s(4, 2, 3) as string
s(3, 1, 2) = thispath$
m = PathAddBackslash(&s(3,1,2))
Print LeftPart$(s(3,1,2), 0)
}
testArr2

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.