Phix object arrays
- Posted by irv Feb 03, 2021
- 804 views
Often it is useful to declare an array of objects; buttons for example, rather than do them individually:
include GtkWindow.e include GtkBox.e include GtkButton.e Window win = new() win.border_width = 10 win.connect("destroy","Quit") Box pan = new() win.add(pan) sequence buttons = repeat(0,5) for i = 1 to length(buttons) do buttons[i] = new(Button) pan.add(buttons[i]) end for buttons[1].label = "One" -- can't do this! buttons[3].sensitive = false -- can't do this either! win.show_all() gtk_main()
/home/irv/pgtk/buttontest.ex:18 buttons[1].label = "One" ^ '=' expectedIt is often necessary to call a method for one or more of the items in the array, but as noted above, can't do that. button.label and button.sensitive are valid for individually declared objects, but not for one picked from a sequence of objects. IOW, subscripts don't work here.
Is there another way?