This LR without a single example is somewhat disconcerting.
Case in point :
[quote]Constructor(other As MemoryBlock)
Creates a new MemoryBlock with the data from an existing MemoryBlock.[/quote]
So why is this saying syntax error ?
dim m as memoryblock
dim mb as memoryblock(m)
Ultimately, I want to put a binarystream read into a memoryblock.
This seems to work, so far :
dim f as folderitem = SpecialFolder.GetResource("myfile.dat")
Dim BS as BinaryStream = BinaryStream.Create(f)
Now I know I can go BS.Read(60) to read 60 bytes and it comes back as a memoryblock. So I am probably very dumb, but I was believing that I could construct a new memoryblock with that read.
We have been spoiled with the old LR. This new thing with no pictures is no fun
I am assuming that you are using the new framework since it’s memoryblock has a constructor from memoryblock. The syntax error is because you left out a "new’. See below:
dim m as xojo.core.memoryblock
dim mb as new xojo.core.memoryblock(m)
dim m as memoryblock
dim mb as NEW memoryblock(m)[/quote]
[quote=159047:@William James]error is because you left out a "new’. See below:
dim m as xojo.core.memoryblock
dim mb as new xojo.core.memoryblock(m)[/quote]
Thank you both. But it crashes And the break in app.unhandledexception never takes place
This works :
dim m as new memoryblock(1)
dim mb as new xojo.core.memoryblock(m)
Now what I wanted to do was to assign the read from a binarystream to the MB memoryblock.
[code] dim f as folderitem = SpecialFolder.GetResource(“myfile.dat”)
dim longueur as integer = f.Length
system.debuglog longueur.ToText
Dim BS as BinaryStream = BinaryStream.Create(f)
dim mb as new xojo.core.memoryblock(BS.Read(f.length))
[/code]
The file length is good, there is no runtime exception in the getresource, but yet, the read triggers a Xojo.io.Exception “Error reading”. I checked the permissions, set chmod to 655, no luck.
[quote=159099:@David Fleming]Would a mutable memory block work?
dim mb as new mutablememoryblock(bs.read(f.length))
[/quote]
No, it does not work either. Since the error is a Xojo.io.exception, it looks like a read permission. But I fail to understand why getresource does find the file fine, and then reading it does not work. Since the file is in the bundle, it is supposed to be read only, so it should work.
I am going to try and copy it to documents and try to read it from there.
Does not work. The folderitem does find and see the file fine. I tried with other types of files to make sure, and it finds the file length fine as well.
What does not work is reading the file. It is apparently not an issue with the binarystream itself, since folderitem.copyfileto() triggers the exception as well.
Now what is strange is that if I try with an image file it does not work either, but if I use iOSImage.FromFile(f) it works fine. So it is not a permission problem. Obviously, there is something wrong in copyFileTo as well as BinaryStream.Read()
I will appreciate some insight from Xojo, at this point.
Actually, maybe I am going to it the wrong way. When dragging a file into the project, does it not become a MemoryBlock ? It would be a lot simpler, then.