[Gambas-user] array of classes
adamnt42 at ...626...
adamnt42 at ...626...
Sun Jul 3 11:38:25 CEST 2016
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
--
B Bruen <adamnt42 at ...3379... (sort of)>
More information about the User
mailing list