Quantcast

array of objects (custom class), bug or error in source ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

array of objects (custom class), bug or error in source ?

cmeladia
This post has NOT been accepted by the mailing list yet.
This post was updated on .
I think I may have found a bug in version 3.5
My simple example with a custom class and a public array.
This example is working properly if the array type is an integer[] but not  if the array type are  objects of my class.

my class Cl1:

' Gambas class file
Public a As Integer

main prog (FMain.class):
' Gambas class file

Public ar As New Cl1[]

Public Sub Form_Open()
 Print ar.Count ' result 0
 fillAr(4)
 Print
 dispAr
End

Public Sub fillAr(n As Integer)
 Dim i As Integer
 Dim b As New Cl1
 For i = 0 To n
   b.a = i * 2
    ar.Add(b)
    Print ar[i].a, 'results : 0 2 4 6 8 'here  ok
 Next  
End

Public Sub dispAr()
 Dim i As Integer
 For i = 0 To ar.Count - 1
  Print ar[i].a, 'results : 8 8 8 8 8 'here the problem, is the ar[] public ?
 Next  
End
---------------------------------------------------------------------------------------------------

The same example with integers works ok :

Public ar As New Integer[]
Public Sub Form_Open()
fillAr(4)
dispAr
End

Public Sub fillAr(n As Integer)
 Dim i As Integer
 For i = 0 To n
   ar.add(i * 2)
    Print ar[i], 'results :0       2       4       6       8
 Next  
 Print
End

Public Sub dispAr()
 Dim i As Integer
 For i = 0 To ar.Count - 1
   Print ar[i], 'results :0       2       4       6       8
 Next  
 Print
End
Loading...