[Gambas-user] Adding Classes to Collections... we can't do this?

sbungay sbungay at ...981...
Mon May 30 00:22:49 CEST 2005


   OK, I'm coming from the VB 6.0 world and I know I know this is not 
VB... I have a question anyway about adding classes to collections. Um.. 
why can't we do this? So far al I can do is add each item in the class 
to the collection... but that is a royal pain in the butt. What I want 
to do is something like this.

'*********** BEGIN SAMPLE CODE ***************************************
'*** This does not work...
Dim MyCollection as New Collection

' The Class has two integer values in it.. X and Y (just for example)
Dim MyClass as XYClass

MyClass = new XYClass

With MyClass
      .X = 10
      .Y = 10
End With

MyCollection.Add(MyClass)

MyClass = NULL  ' Is this equiv. to the VB "Set MyClass = Nothing"


'*** This DOES work but is kludgy
Dim MyCollection as New Collection

' The Class has two integer values in it.. X and Y (just for example)
Dim MyClass as XYClass

MyClass = new XYClass

With MyClass
      .X = 10
      .Y = 10
End With

MyCollection.Add(MyClass.X, MyClass.Y)

MyClass = NULL  ' Is this equiv. to the VB "Set MyClass = Nothing"


'*********** END SAMPLE CODE ***************************************

   Now froma programming standpoint I like the first way better because 
I  simply add the created class to the collection. Wonderful, less 
typing for me.
   Does the problem stem from collection only being able to hold Variant 
types?




More information about the User mailing list