On Mar 20, 2006, at 3:58 PM, Jay Rimalrick wrote:
Is there a way to access an object in a dictionary without having
to remove the object and then re-add the object?
You don't remove it when you access it using Dictionary.Value().
Instead you are getting a reference (like a pointer) to the object.
The object remains in the dictionary until you overwrite or remove
the value.
For example:
Dim d As New Dictionary
Dim m As MemoryBlock = NewMemoryBlock(3) // our test object
// add some data to the test object
m.Byte(0) = 0
m.Byte(1) = 1
m.Byte(2) = 2
m.Byte(3) = 3
d.Value("mb") = m // add memoryBlock to dictionary
// this creates a second reference to the MemoryBlock object (if
exists)
Dim mb2 As MemoryBlock = MemoryBlock(d.Lookup("mb", Nil))
If Not (mb2 Is Nil) Then
mb2.Byte(0) = 3
mb2.Byte(1) = 2
mb2.Byte(2) = 1
mb2.Byte(3) = 0
End If
// since we still have a reference to "m" output the results
MsgBox Str(m.Byte(0)) + Str(m.Byte(1)) + Str(m.Byte(2)) + Str
(m.Byte(3))
// notice that the MsgBox output is "3210", not "0123" like
original values
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>