CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    thanks my friend
    i will see it in weekend. thanks

  2. #17
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    i know programming but sometimes(in these case in VB6), when i program, some strange things appens
    like some code is working now, then(without change) isn't....
    honestly i don't understand
    because now i have some problems in my Sprite control
    can you spend some time with me for resolve them?
    (if you can use messenger/msn greate, if not that's ok)
    thanks

  3. #18
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Destroying objects that was builded in project-mode

    You can always go back to your old code, when it was working right
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #19
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    Quote Originally Posted by dglienna View Post
    You can always go back to your old code, when it was working right
    yeah, thanks for the advice.
    i need ask you something...
    in UC, i need activate a API functions(like message windows(winproc()), but i don't know what event must use. because the initializate event is only for change the variables(i can't use it for more)... i could use the show event, but the show event is call it when it's created(with or without image/backcolor)?
    i know i thing, the terminate event is called when the UC is created... why? can i ignore it(when is created)?
    thanks

  5. #20
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Destroying objects that was builded in project-mode

    I don't understand the question
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #21
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    Quote Originally Posted by dglienna View Post
    I don't understand the question
    i'm sorry i will say in other words...
    when the UC is created, why the Finalizate event is called? these event can be ignored when the UC is created?
    anotherthing when the UC is created the Initializated event is called, but i only can change the variables values.... when the UC is created(Visible can or not be true, doesn't mine), the Show event is always called?
    thanks

  7. #22
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    ok.. now i can continue with our conversation
    i need build an Destroy method(i don't care if the object was created in Load function or in project-mode). can you advice me?
    or give me informations?
    thanks

  8. #23
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Destroying objects that was builded in project-mode

    Objects which are created at design-time cannot be destroyed at runtime. However, if you create an array, then additional elements can be loaded and unloaded at runtime. Still, the one you created at design-time must remain.

    In the case of your sprites, one could be placed on the form at design-time, with an Index of zero. The other sprites would then be loaded/unloaded at runtime.

    <EDIT>
    Additionally, a UserControl cannot unload itself. The controls should be loaded and unloaded by the program in which they are used.
    Last edited by WizBang; September 22nd, 2009 at 11:24 AM.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #24
    Join Date
    Apr 2009
    Posts
    1,357

    Re: Destroying objects that was builded in project-mode

    Quote Originally Posted by WizBang View Post
    Objects which are created at design-time cannot be destroyed at runtime. However, if you create an array, then additional elements can be loaded and unloaded at runtime. Still, the one you created at design-time must remain.

    In the case of your sprites, one could be placed on the form at design-time, with an Index of zero. The other sprites would then be loaded/unloaded at runtime.

    <EDIT>
    Additionally, a UserControl cannot unload itself. The controls should be loaded and unloaded by the program in which they are used.
    i'm sorry can you give me a simple(very simple) project that can create objects(with array and without array) simple in run-time?
    thanks

  10. #25
    Join Date
    Dec 2001
    Posts
    6,332

    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?

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured