[Gambas-user] Not sure on declaring user-defined datatype arrays

ron ronstk at ...239...
Fri Apr 30 21:34:27 CEST 2004


On Friday 30 April 2004 21:13, Grahame White wrote:
> What I have at the moment is three class files
>
> Global.class
> Object.class
> FMain.class
>
> Thingy.class contains
>
> 	PUBLIC Name AS String
> 	PUBLIC Height AS Short
> 	PUBLIC Width AS Short
>
> Global.class contains
>
> 	PUBLIC STATIC Pile AS Object[]
>
> FMain.class contains
>
> 	PUBLIC SUB Form_Show()
>
> 		tmp_object AS NEW Thingy
>   		DIM i AS Byte
>
> 		' Create two elements in the Pile array
>   		FOR i = 1 TO 2
>     			Global.Pile.Add(Thingy)
> 		NEXT
>
> 		WITH Global.Pile[0]
> 			.Name = "Square"
> 			.Height = 10
> 			.Width = 10
> 		END WITH
>
> 		WITH Global.Pile[1]
> 			.Name = "Rectangle"
> 			.Height = 20
> 			.Width = 10
> 		END WITH
>
> 	END
>
>
> To my mind this should create an array of Thingy that is two elements big.
>
> However when I step through the code with the debugger with a watch on :
> Global.Pile[0].Name and on Global.Pile[1].Name
>
> it gets to the line .Name = "Square" and instead of only setting
> Global.Pile[0].Name to Square it ALSO sets Global.Pile[1].Name to Square
>
> What am I doing wrong?
>
> Grahame

Well i understand you want a pile of thingy's
you create now only 1 new thingy and add this to the array
the second loop in the for/next add simple the same thingy
move the 'tmp_object AS NEW Thingy' inside the for next loop will
make new objects to add instead of the only 1 you have now

Ron




More information about the User mailing list