Make object unique

sterlingy

Active Member
Licensed User
Longtime User
I have two objects of the same type

Code: Copy
Private tempBMPData, setupBMPData As BitmapData

Then I want to make one equal to the other

Code: Copy
tempBMPData = setupBMPData

The problem is that when I CLEAR setupBMPData, it also clears tempBMPData. I don't want both variables pointing to the same object. How do I copy the contents of one variable to the other, but keep them pointing to separate objects?

-Sterling
 
You would have to copy the individual items
Code: Copy
Dim tempBMPData, setupBMPData As BitmapData
...
tempBMPData.Bitmap = setupBMPData.Bitmap
tempBMPData.SrcRect = setupBMPData.SrcRect
tempBMPData.DestRect = setupBMPData.DestRect
tempBMPData.Rotate = setupBMPData.Rotate
tempBMPData.Flip= setupBMPData.Flip
You now have two instances of BitmapData but note that they share three reference objects. Bitmap, SrcRect and DestRest. This may or may not be what you want. If you want a truly independent copy you would need to clone those objects. I haven't tested the following but it looks OK at first sight.
Code: Copy
Dim tempBMPData, setupBMPData As BitmapData
...
Dim newSrcRect, newDestRect As Rect
Dim newBitmap As Bitmap

newBitmap.Initialize(setupBMPData.Bitmap)
tempBMPData.Bitmap = newBitmap
newSrcRect.Initialize(setupBMPData.SrcRect.Left, setupBMPData.SrcRect.Top, setupBMPData.SrcRect.Right, setupBMPData.SrcRect.Bottom) 
tempBMPData.SrcRect = newSrcRect

newDestRect.Initialize(setupBMPData.DestRect.Left, setupBMPData.DestRect.Top, setupBMPData.DestRect.Right, setupBMPData.DestRect.Bottom) 
tempBMPData.DestRect = newDestRect

tempBMPData.Rotate = setupBMPData.Rotate
tempBMPData.Flip= setupBMPData.Flip
You might want to ask yourself if you really need a deep copy like this or if you can avoid having to do it.
 
Upvote 0
The first option would probably do it, but I should have been clearer. I'm really trying to clone a GameView, in which the BitmapsData is a LIST. I'll try to figure it out. If you have some ideas, I'd love to see 'em.

-Sterling
 
Upvote 0
Back
Top