forum-msg-id-135696-edit

Original date:2021-02-03 10:44:09 Edited by: petelomax Subject: Re: Phix object arrays

irv said...

/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?

The compiler needs a type hint, for example

Button b = buttons[1] 
b.label = "One" 

or maybe

procedure set_label(Button b, string label) 
    b.label = label 
end procedure 
set_label(buttons[1],"One") 

Unfortunately it's just not smart enough to figure out that buttons[1] is a Button instance, not entirely dissimilar to

    Button b = new()            -- ok 
--  buttons[i] = new()          -- not ok 
    buttons[i] = new(Button)    -- ok 

In fact, I'll go so far as to recommend this version of your above for loop (one more line, but also one less subscript):

for i = 1 to length(buttons) do  
  Button b = new() 
  buttons[i] = b 
  pan.add(b)  
end for  
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu