[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-user
Subject:    [Gambas-user] Minor bug with READ & WRITE commands?
From:       "Jussi Lahtinen" <jussi.lahtinen () gmail ! com>
Date:       2009-01-15 19:13:27
Message-ID: 384d3900901151113w73982792k14ad2b8424bf812b () mail ! gmail ! com
[Download RAW message or body]

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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic