|
-
September 23rd, 2009, 05:26 AM
#8
Re: Destroying objects that was builded in project-mode
Simply place one object on the form, and set the Index property to zero. This will create an array.
Then at runtime:
Code:
Private Sub CreateSprite(X As Long, Y As Long, Color As Long)
Dim I As Long
I = MySpriteArray.UBound + 1
Load MySpriteArray(I)
MySpriteArray.Move X, Y
MySpriteArray.ForeColor = Color
MySpriteArray.Visible = True
End Sub
Private Sub KillSprite(Index As Long)
Unload MySpriteArray(Index)
End Sub
You can create the first element with an Index other than zero, if you want. Note also that elements can be unloaded in any order. So the UBound of the array will not be the same as the Count. In other words, if you have 5 elements (Indexes of 1 to 5), and you unload number 2, the UBound will still be 5, while the Count is 4. This means that you may encounter errors if you try to iterate through an array after unloading one or more elements where the Index is not the UBound.
Objects can be created at runtime without being part of an array, but in that case you will not be able to catch the events without subclassing, which will very likely bring you many headaches.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|