[Gambas-user] array of classes

Shane buster6seven at ...626...
Sun Jul 3 12:42:12 CEST 2016


FYI this will not work as is as i found out

Public Sub Main()

Dim idx as integer
Dim hBlock as Block

For idx = 0 to MAX_BLOCKS-1
  hBlock = new Block	
  Blocks[idx] = hBlock
Next

must be this way or in my case it did work as i was filling new values 
in the
loop

On 03/07/16 19:38, adamnt42 at ...626... wrote:
> On Sun, 3 Jul 2016 18:20:15 +1000
> Shane <buster6seven at ...626...> wrote:
>
>> I'm trying create a array of myClass but when i create it i have an
>> array of null values
>>
>> i have my Rect.class
>>
>> Public x As Integer
>> Public y As Integer
>> Public width As Integer
>> Public height As Integer
>>
>>
>> then my Block.class
>>
>> Public Screenpos As New Rect
>> Public Imagepos As New Rect
>> Public num_hits As Integer
>>
>> and then in the main module i do
>>
>> Public Blocks As New Block[MAX_BLOCKS]
>>
>> and i get an array with Max_BLOCKS indexes on null values
>>
>> what am i doing wrong
>>
>> thanks Shane
>>
>>
>>
> Well at first glance I'd tend to say - nothing!
> Declaration of the array in your main module is doing exactly what it should.  Creating an empty array (presumably of length MAX_BLOCKS).
> If you were expecting that you would have an array of length MAX_BLOCKS completely populated with some form of Block objects then this is not what you are going to get.
>
> Try (in the Main module)
> Public Blocks As New Block[MAX_BLOCKS]
>
> Public Sub Main()
>
> Dim idx as integer
> Dim hBlock as new Block
>
> For idx = 0 to MAX_BLOCKS-1
>    Blocks[idx] = hBlock
> Next
>
> etc
>
>
> Or have I misunderstood?
>
> hth
> Bruce
>





More information about the User mailing list