[Gambas-user] Arrays of Structs

Fabien Bodard gambas.fr at ...626...
Wed Nov 30 16:03:55 CET 2016


no

2016-11-30 15:46 GMT+01:00 Rolf-Werner Eilert <eilert-sprachen at ...221...>:
> Would this be possible?
>
> Static Private WorldMap[100, 100] As New MapObject
>
>
> or in a similar way... Just ask because I tend to use New in the first
> declaration line if possible.
>
> Regards
> Rolf
>
> Am 30.11.2016 07:27, schrieb nando_f at ...951...:
>> I use structs to write binary to a file in struct order.
>> Nice and easy.
>> Not so easy with a class.
>>
>> Your example is possible.  I have done similar.
>>
>> The STRUCT only defines the structure...it doesn't create the memory allocation.
>> Static Private WorldMap[100, 100] As MapObject  just defines arrays to point to objects.
>> You need to run code to actually create new objects at each array element.
>> hint:
>> Loop  x
>>   Loop  y
>>     [x][y] = new MapObject  'the new actually creates a memory allocation for it.
>>
>> -Fernando
>>
>> --
>> Open WebMail Project (http://openwebmail.org)
>>
>>
>> ---------- Original Message -----------
>> From: Tony Morehen <tmorehen at ...3602...>
>> To: gambas-user at lists.sourceforge.net
>> Sent: Tue, 29 Nov 2016 15:29:03 -0500
>> Subject: Re: [Gambas-user] Arrays of Structs
>>
>>> I may just be responding to a typo but your struct is named MapObjec
>>> while the code using it refers to MapObject.
>>>
>>> On 28/11/16 10:40 PM, Cam Era wrote:
>>>> I expect I'm trying to do something that's not possible with Gambas, but
>>>> I'll ask this anyway.
>>>>
>>>> I'm trying to create an n x n array of a STRUCT which itself contains an
>>>> array of type STRUCT.
>>>>
>>>> I have this declaration:
>>>>
>>>>       Public Struct MapObjec
>>>>         xPos As Integer
>>>>         yPos As Integer
>>>>         ObjectType As Integer
>>>>         isVisible As Boolean
>>>>         ObjectPicture As Picture
>>>>       End Struct
>>>>
>>>>       Public Struct MapRoom
>>>>         MapObjects[50] As MapObject
>>>>       End Struct
>>>>
>>>>       Static Private WorldMap[100, 100] As MapObject
>>>>
>>>>
>>>> and this code:
>>>>
>>>>       WorldMap[5, 10].MapObjects.yPos = 100
>>>>
>>>>
>>>> which generates a "NULL object" error.
>>>>
>>>> Any pointers as to whether this is possible and if so, how?
>>>>
>>>>
>>>> Cheers
>>>>
>>>> -- Cam
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> Gambas-user mailing list
>>>> Gambas-user at lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Gambas-user mailing list
>>> Gambas-user at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> ------- End of Original Message -------
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Fabien Bodard




More information about the User mailing list