where mb is a MemoryBlock from a database blob. This constructor, of course, does not work in Android so I was wondering what a simple workaround would be to extract a series of numbers from the binary stream. The complete code looks like
bs = new BinaryStream(mb)
bs.LittleEndian = True
npath = bs.ReadInt64 // the number of paths
for i = 0 to npath
tempPath = new pathClass
nvert = bs.ReadInt64 // the number of Vertices
for j = 0 to nvert
tempVert = vertexFromLonLat(bs.ReadDouble, bs.ReadDouble)
tempVert.up = bs.ReadDouble
if tempVert.up < 0 then Continue // outside of map/DEM area
tempPath.vert.Add tempVert
next
tempBed.paths.Add tempPath
next
bs.Close
What would be the most efficient way to achieve the same thing Android?
var p as Ptr
p = mb
npath = p.UInt64
p = p + 8
for i = 0 to npath
nvert = p.UInt64
p = p + 8
for j = 0 to nvert
tempVert = vertexFromLonLat(p.Double, p.Double(8))
p = p + 16
// etc.
Thanks very much, Tim, for the suggestion and my apologies for not acknowledging it sooner. I have to say, Xojo’x Android is driving me crazy and still very much deserves its beta status.
It turns out the using a Ptr as you suggest does not work because one cannot just add 8 to the pointer. However, it seems that the following code should work:
Var mb as MemoryBlock
Var offset as integer = 0
nPaths = mb.UInt64Value(offset)
offset = offset + 8
for i as integer = 0 to nPaths
nVerts = mb.UInt64Value(offset)
offset = offset + 8
for j as integer = 0 to nVerts
tempVert = vertexFromLonLat(mb.DoubleValue(offset), mb.DoubleValue(offset+8))
offset = offset + 16
// etc.
But it doesn’t. It seems to read the Uints okay but not the doubles.
This is all being made very much harder than it should be because the debugger does not seem to be updating its values as one steps through the code. I can have a simple assignment of a value in code:
s = "Quick brown fox"
n= 5
and the debugger will step through those lines and continue to report that s = ““ and n = 0, MemoryBlocks are reported as Nil when I know they are not. Although I have not been able to successfully parse MemoryBlocks,I did manage to get PictureValues out of a SQLite DB to display on the screen but these map tiles are 256 x 256 pixels yet are displayed in the canvas at about 96 x 96 pixels but because Xojo Android doesn’t yet support Picture.HorizontalResolution (or vertical) I can’t tell what res the Android app thinks they are. Don’t get me started on ByRef… These functions all work perfectly in the iOS project that I am trying to translate.
Those of you who have done useful work making Android projects in Xojo, you have my admiration. In my experience so far it is a complete mess.
Okay, which more experimentation, it appears to be a bug with Xojo Android reading blob columns into a MemoryBlock. You can find my bug report and sample project here:
In brief, the blob in the database has a significantly smaller number of bytes than the size of the MemoryBlock that Xojo Android creates from the blob (e.g., 2344 bytes in the DB and 3762 bytes in the MemoryBlock). This would seem to be a critical bug given that most GIS type systems store MultiLineStrings as blobs in databases (e.g., in the GeoPackage or SpatiaLite formats). I also wonder whether this bug is behind Android rendering my 256x256 pixel map tiles into little more or less 96x96 pixel postage stamps with seemingly blank spaces in between. Hope this gets fixed in the next release.