Re: Phix object arrays
- Posted by irv Feb 03, 2021
- 895 views
Simplest solution seems to be to forget making an array, and just name the items.
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) for i = 1 to 5 do Button x = new() x.label = sprintf("Button %d",i) x.name = sprintf("B%d",i) -- name 'em. x.connect("clicked","Toggle") -- any button click calls Toggle() pan.add(x) end for win.show_all() gtk_main() public function Toggle() Object y = from_name("B2") -- retrieve by name, -- some various ways to toggle: y.sensitive = not y.sensitive --[A] works -- Warning sq_not assumed y.sensitive = not(y.sensitive) --[B] works -- same warning y.sensitive = (y.sensitive = 0) --[C] works -- no warning, but awkward y.sensitive = sq_not(y.sensitive) --[D] works -- no warning, strange syntax -- What am I missing here? -- Shouldn't [A] or [B], the most "normal" syntax, -- be the default and not issue a warning? -- After all, y.sensitive is not a sequence, it is a boolean, -- so assuming that it needs a sequence operation is wrong somehow. return 1 end function
Further testing proves that this method works OK for buttons, because there are rarely going to be more than a few. For menus, it requires far too much work, too many lines of code. It's going to be necessary to find a way to use arrays of widgets in some manner. Perhaps a WidgetArray class?