forum-msg-id-135695-edit

Original date:2021-02-03 10:24:15 Edited by: irv Subject: Phix object arrays

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.

Is there another way?

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu