Appending to a MemoryBlock

  1. 8 weeks ago

    Garry P

    Sep 16 Pre-Release Testers, Xojo Pro Europe (Torquay, UK)

    Is it possible to append one MemoryBlock to another?

    I see that there is an Append method for the Xojo.Core.MutableMemoryBlock but I am using the classic MemoryBlock. For example, could I append a Double to the end of an existing MemoryBlock?

  2. Kem T

    Sep 16 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    You have to do it manually. Change the size of the first, then use StringValue (or whatever is appropriate) to grab the value from the second.

  3. Garry P

    Sep 16 Pre-Release Testers, Xojo Pro Europe (Torquay, UK)

    I've just been playing around with this. It looks like Operator_Add has been been overridden for MemoryBlocks so it's as easy as this:

    Dim mb1 As MemoryBlock = "Hi" // Bytes are: 72, 105
    Dim mb2 As New MemoryBlock(8)
    mb2.DoubleValue(0) = 42.5 // Bytes are: 0, 0, 0, 0, 0, 64, 69, 64
    
    mb1 = mb1 + mb2
    // mb1 bytes are now:  72, 105, 0, 0, 0, 0, 0, 64, 69, 64

    Guess I shouldn't have been over-thinking it...

  4. Norman P

    Sep 16 Pre-Release Testers, Xojo Pro
    Edited 8 weeks ago

    indeed yet it appears to be undocumented http://docs.xojo.com/MemoryBlock
    There are

    Operator_Add(value As MemoryBlock) As MemoryBlock
    Operator_Compare(value As MemoryBlock) As Integer

    as well as the convert to and from Ptr and String

    Feedback Case #57468

  5. Kem T

    Sep 16 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Good to know, especially since I'll be giving a talk on this at XDC.

or Sign Up to reply!