Phix object arrays

new topic     » topic index » view thread      » older message » newer message

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"  
          ^ '=' expected 
It 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?

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu