MemoryBlock.Ptr
From Xojo Documentation
Method
Gets or sets a Ptr. Offset is in bytes from the beginning of the MemoryBlock. If the Ptr is to a MemoryBlock, it will be of an unknown size when retrieved. Size will be set to -1 but it still can be used to access its data.
Notes
Note the difference between
and
The former gets a Ptr to the MemoryBlock itself while the latter retrieves the Ptr that is stored at offset n within the MemoryBlock.
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(4)
Var p As Ptr = MBProperty
mb.Ptr(0) = p
MBProperty.StringValue(0, 8) = "a string"
Var mb As New MemoryBlock(4)
Var p As Ptr = MBProperty
mb.Ptr(0) = p
Because of implicit conversion between a Ptr and MemoryBlock, this can be shortened.
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)
Var s As String = mb1.StringValue(0, 8)
This code will store a Ptrs to two methods.