Disposing Controls

Discussion in 'Questions (Windows Mobile)' started by RandomCoder, Feb 18, 2008.

  1. RandomCoder

    RandomCoder Well-Known Member Licensed User

    It was my understanding that if a Panel or Form was disposed then all controls belonging to that Panel/Form would also be disposed.
    However my latest app has shown that this is not the case.
    Is this a change with V6 or am I just mistaken, as it appears to be undocumented?

    I'm now using the GetControls method to dispose of all controls on a panel prior to disposing the panel which is working, however I also have a few objects which are not disposed using this method.
    Is there a way to determine what objects are present and then can I dispose them?

    MarcTG likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Forms can't be disposed.
    When you dispose a panel only the panel gets disposed.
    You can use something like:
    somearray() = GetControls("Panel1")
    for i = 0 to ArrayLen(somearray())-1
    This is not so elegant but it will work (to find if a specific control exists):
    Sub ControlExist(crl)
    a = ControlType(crl)
    return true
    return false
    End Sub
  3. willisgt

    willisgt Active Member Licensed User

    I have often used an ArrayList to store the names of all the controls I create dynamically. This works well if I just want to know if a control exists.

    More recently, I've switched to using a table, as I can also store the name of the control's parent (form, panel, etc), type, and other stuff I might want to keep track of.

    Naturally, it's a simple matter to add an item to an array list - or a row to a table - when a control is created, and to remove it when a control is disposed of.

  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Thanks Erel.
    Although the help file states that Forms do indeed have a Dispose property.

    I'm currently using a similar code to yours to dispose of the controls on a panel but what about Objects?
    Can I use a method to determine what Objects are present on the panel and then dispose them?
    Ideally I would like to create and dispose of the tree view, context menu's and SMS messages as and when required, although if not possible then I will add at the start of the program and leave in place.

  5. RandomCoder

    RandomCoder Well-Known Member Licensed User

    From the lack of responses, do I take it that it's not possible to determine what objects are in use (other than keeping my own record in an array list) and that I can't dispose of them anyway?

  6. Erel

    Erel Administrator Staff Member Licensed User

    GetControls("") will return all controls and objects.
    You could dispose objects the same way you dispose other controls.
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I will double check the problem I was having and report back later (about to leave for work now :sign0148:).
    Thanks for the reply.

  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I found my problem as demonstarted in my sample code attached (just add ControlsEx.Dll to the same dir)...

    It appears that Objects do not belong to the panel/form they are applied to, niether do they belong to the main form.

    Now that I know this, disposing them is not a problem, I'll just keep track of which ones I need to delete.
    My original intention was just to pass a sub the panel name and have it automatically delete all controls associated with it, I'll just need to re-work this slightly.

    Thanks for the assistance.


    Attached Files:

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice