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

Grahame White grahame at ...307...
Fri Apr 30 21:13:49 CEST 2004


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




More information about the User mailing list