From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

MemoryBlock.Ptr(offset As Integer) As MemoryBlock

Supported for all project types and targets.


MemoryBlock.Ptr(offset As Integer, Assigns value As MemoryBlock)

Supported for all project types and targets.

Gets or sets a MemoryBlock at the specified offset. Offset is in bytes from the beginning of the MemoryBlock.


If the MemoryBlock's size is not known, then the MemoryBlock this returns will also have an unknown (-1) size, although it can still be used to access its data.

MemoryBlocks automatically convert to Ptr.

This code converts a MemoryBlock to a Ptr:

Var p As Ptr = mb

This code retrieves another MemoryBlock (within the original MemoryBlock) at the specified offset and converts it to a Ptr:

Var p As Ptr = mb.Ptr(n)

Sample Code

This example stores a Ptr to a MemoryBlock property. If the MemoryBlock property goes out of scope, the Ptr will be invalid when retrieved.

MBProperty = New MemoryBlock(8)
MBProperty.StringValue(0, 8) = "a string"

Var mb As New MemoryBlock(8)
Var p As Ptr = MBProperty
mb.Ptr(0) = p

Because of implicit conversion between a Ptr and MemoryBlock, this can be shortened.

Var mb As New MemoryBlock(4)
mb.Ptr(0) = MBProperty

This code will retrieve the MemoryBlock later.

Var mb1 As MemoryBlock = mb.Ptr(0) // Size will be unknown (-1)
Var s As String = mb1.StringValue(0, 8)

This code will store a Ptrs to two methods.

Var mb As New MemoryBlock(8)
mb.Ptr(0) = AddressOf someMethod
mb.Ptr(4) = AddressOf someOtherMethod