[Gambas-user] Control arrays
Rob
sourceforge-raindog2 at ...94...
Mon Jul 21 00:18:46 CEST 2003
On Sunday 20 July 2003 17:05, Ahmad Kamal wrote:
> 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
Gambas doesn't have any way to make an array of controls graphically yet. You
can assign them to groups for handling of events, but that doesn't really
give you any of the other benefits of control arrays. The best I've come up
with is to do it once in code and then treat it the same as in VB. Warning:
pseudo-code ahead, I don't have any projects handy where this is done.
public Labels as Object[]
...
(in form load event handler)
labels = new Object[10]
labels[0] = Label0
labels[1] = Label1
...
labels[9] = Label9
...
(then, in some other routine)
for i =1 to 10
labels(i).forecolor=Color.Green
next
If you have more than a handful of controls to be put into the array, it might
be better to create the controls in code at runtime rather than using the
form editor and manually putting them into the array.
In any case, you would then want to put all those controls into a group (in
code it's something like mycontrol = new Label as Labels) so that you can
handle all the events with one bit of code.
Rob
More information about the User
mailing list