[Gambas-user] About changes in ListView, TreeView & ColumnView

Benoit Minisini gambas at ...1...
Sun Dec 14 21:42:43 CET 2003


On Sunday 14 December 2003 16:13, Nelson Ferraz wrote:
> Benoit Minisini wrote:
> > I want to change the Dir$() function. Instead of behaving like the VB
> > one, I want it to return a Array of file names. This way, it will be
> > simpler to browser a directory. What do you think about that ?
>
> This is a good idea.
>
> The function could return a single value OR an array, depending on context:
>
>    myItem  = Dir$() ' return a single item
>    myArray = Dir$() ' return an array

There is no 'context' in Gambas. A function cannot know anything about where 
its return value will be stored. It is a matter of encapsulation. So Dir$() 
will return a String array.

>
> Another thing, it would be interesting to have the following methods to
> deal with arrays: Shift, Unshift, Push and Pop.

Hey... Push() and Pop() already exist !

>
>    item = Shift (array)  ' get first item
>    Unshift (array, item) ' insert an item at first position
>
>    Push (array, item)    ' insert an item at last position
>    item = Pop (array)    ' get last item

You can do: MyArray.Add(Item) or MyArray.Push(Item) to insert an item at the 
last position, and MyArray.Add(Item, 0) to insert an item at the first 
position.

>
> The Shift method, in particular, could be useful to emulate the former
> behaviour. Something like this:
>
> myAray = Dir$()
> WHILE (myArray)
>    myItem = Shift (myArray)
>    ' do something with myItem
> END

This is not a good idea to do that in Gambas with array. Removing an array 
element has a big cost, because the array may be reallocated.

Maybe I should add linked list datatype, named 'List' for example.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...





More information about the User mailing list