[Gambas-user] Control arrays
Benoit Minisini
gambas at ...2...
Mon Jul 21 20:53:13 CEST 2003
Le Dimanche 20 Juillet 2003 23:05, Ahmad Kamal a écrit :
> hi all,
>
> I am currently writing a TicTacToe game on GB. I already wrote it on VB,
> so it's a matter of porting. The game of course consists of 9 identical
> squares, in VB I made a control array. I know GB misses one, how can I do
> something like:
>
> for i =1 to 10
> label(i).forecolor=vbGreen
> next
I'm not sure that arrays of controls defined at development time is useful.
If all the controls have the same container, then the following is sufficient
to browse the controls :
FOR EACH hCtrl IN hContainer.Children
...
NEXT
If all the controls must have the same behaviour, the (Group) property is
sufficient.
In your case, if you want to use nine times the same control to make the TIC
TAC TOE game, then I suggest you creating them at runtime. This way, you will
be able to create a N x N game easily.
' Note: the following is a compound array, a VB-like array. This is completely
' different from Object[] that is a object array, ie a Java-like array.
' The compound array is allocated inside the object where it is declared.
' The other array is a real object allocated on the heap.
PRIVATE hSquare[3, 3] AS Object
FOR X = 0 TO 2
FOR Y = 0 TO 2
hSquare[X, Y] = NEW Label(hContainer) AS "TicTacToeSquare"
...
NEXT
NEXT
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list