Arraylist

Discussion in 'Questions (Windows Mobile)' started by tvrman, Jun 29, 2007.

  1. tvrman

    tvrman Member Licensed User

    Help!,

    How can i clear an Arraylist?

    i use
    Listbox3.Clear
    FileSearch (al1, appPath, "*.csv")
    For i = 0 to al1.Count - 1
    ListBox3.Add(FileName(al1.Item(i)))
    Next
    End Sub


    I need serveral times to reload above situations in an listbox, the listbox can be cleared but the Arraylist not?
     
    Last edited: Jun 29, 2007
  2. tvrman

    tvrman Member Licensed User

    i found it ,
    :sign0013:

    al1.clear

    :)
     
  3. sirnono

    sirnono New Member

    Arraylist disposal

    Hi Erel,

    I take benefit of this new subject about Arraylists to ask if there is a way to dispose Arraylists objects added at runtime ?

    In fact, if i add a button to a form with the AddButton method then dispose and add it again, there is no problem.

    But doing the same with an arraylist raises an error.

    eg.:

    ' working code

    AddButton("Form1","myButton",10,10,50,20,"Test")
    msgbox("button added")
    control("myButton").dispose
    msgbox("button disposed")
    AddButton("Form1","myButton",10,10,50,20,"Test")
    msgbox("button added again")

    ' not working code

    AddArrayList("myList")
    msgbox("arraylist added")
    control("myList").dispose
    msgbox("arraylist disposed but in fact not really :)")
    AddArrayList("myList")
    msgbox("well error on above line")

    Well it is still possible to clear the arraylist and add an error handler when trying to add one but i only wanted to know if this was a normal/wanted behaviour.

    Thanks in advance.

    ps: I attached some code example to illustrate :)
    This example also shows how to use a hidden disposable listbox control to mimic the arraylist behaviour.
    The drawbacks of this is we need a form to add the listbox to and the list cannot be sorted automatically with a 'sort method' :/
    There may be other drawbacks not mentionned or just forgotten here ;)
     

    Attached Files:

  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I've tried myself and couldn't get it to work.
    At first I thought that it might not work with the Control keyword and so attempted to Dispose it directly.
    However a quick glance at the help-file and it appears that the Dispose Method is not available for an ArrayList - Sorry.

    Regards,
    RandomCoder
     
  5. Cableguy

    Cableguy Expert Licensed User

    If you are going to use the same arraylist then try just to clear it...
    You can check that an array list already exist by trapping the error generated upon trying to re-create it...
    like this

    errorlabel(error)
    addarraylist(myarray) ' if myarray already exist it jumps to error
    return ' stops the execution of the remaing code of the sub
    error:
    do whatever you like, possably create "myarray2"
     
  6. sirnono

    sirnono New Member

    To CableGuy, yep, we need to use errorlabel not to get the error message.

    To RandomCoder, the dispose method does not appear in the help file but seems to exist anyway :confused:

    If you add one arraylist manually with the form editor then in the code you tap "arraylist1." to see the possible methods you will notice the dispose one.

    Is this only a method provided by a generic interface with no implementation behind or why in any other case does this method seem to be available ?

    Thanks for your replies ;)

    Regards,
    Sirnono
     
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    This would appear to be a bug and so I'll add it to the 'Bugs and Errors' section of the Forum.
    It should either be made available as a Method or removed from the list.

    Regards,
    RandomCoder.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    The dispose method is not implemented for ArrayLists.
     
Loading...