[Gambas-user] Minor bug with READ & WRITE commands?

Jussi Lahtinen jussi.lahtinen at ...626...
Thu Jan 15 20:13:27 CET 2009


Hi!

Here is my test code (first with errors) for pass array of objects
byref to external function:

PUBLIC SUB Button4_Click()
DIM ii AS Integer
DIM pResult AS Pointer
DIM fResult AS NEW Object[]
DIM aa AS Class1

FOR ii = 0 TO 9
aa = NEW Class1
aa.x = 100
aa.y = 200
fResult.Add(aa)
NEXT

pResult = Alloc(8, 10)

FOR ii = 0 TO 9
WITH fResult[ii]
WRITE #pResult + (ii * 8), .x
WRITE #pResult + ((ii * 8) + 4), .y
END WITH
NEXT

GetAStruct(pResult)

FOR ii = 0 TO 9
WITH fResult[ii]
READ #pResult + (ii * 8), .x
READ #pResult + ((ii * 8) + 4), .y
END WITH
NEXT

Free(pResult)

FOR ii = 0 TO 9
PRINT fResult[ii].x & " " & fResult[ii].y
NEXT '

END


Line: READ #pResult + (ii * 8), .x
Gives error; Type mismatch: wanted Integer, got String instead. ??

And line: WRITE #pResult + (ii * 8), .x
Writes rubbish into memory. No error messages.

If I change code this way, it works perfectly:

PUBLIC SUB Button4_Click()
DIM ii AS Integer
DIM pResult AS Pointer
DIM fResult AS NEW Object[]
DIM aa AS Class1
DIM kk AS Integer

FOR ii = 0 TO 9
aa = NEW Class1
aa.x = 100
aa.y = 200
fResult.Add(aa)
NEXT


pResult = Alloc(8, 10)

FOR ii = 0 TO 9
WITH fResult[ii]
kk = .x
WRITE #pResult + (ii * 8), kk
kk = .y
WRITE #pResult + ((ii * 8) + 4), kk
END WITH
NEXT

GetAStruct(pResult)

FOR ii = 0 TO 9
WITH fResult[ii]
READ #pResult + (ii * 8), kk
.x = kk
READ #pResult + ((ii * 8) + 4), kk
.y = kk
END WITH
NEXT

Free(pResult)

FOR ii = 0 TO 9
PRINT fResult[ii].x & " " & fResult[ii].y
NEXT '

END


Strange thing is that the whole code has no string on it.
Class1:
PUBLIC x AS Integer
PUBLIC y AS Integer


So, why .x is "string" ?
Is there better way to do this (@ Gambas2.10.2)?


Jussi




More information about the User mailing list