Re: Phix+EuGTK

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

Both windows have the same "handle". How can I change my code so each call to new() will call the "gtk_window_new" function again to get a new unique handle?

Yeah, inline field defaults like that are evaluated precisely once.

The sure-fire solution looks like this

class window 
    integer handle 
    procedure show() ? handle end procedure 
end class 
window w1 = new({rand(99)}), 
       w2 = new({rand(99)}) 
w1.show() 
w2.show() 

I ran out of steam on constructors, so they're incomplete, undocumented, and possibly subject to change (eg, dunno why I made em functions).

class window 
    integer handle 
    function window() 
        this.handle = rand(99) 
        return this 
    end function 
    procedure show() ? handle end procedure 
end class 
window w1 = new(), 
       w2 = new() 
w1.show() 
w2.show() 

Optional parameters aren't as flexible in Phix as they are in OE, they only support entirely fixed constants and single-level calls of length(), command_line(), routine_id(), platform(), machine_bits(), and machine_word(), rather than full expressions. I could perhaps take another run at that if it's genuinely going to help, but I'll probably just run into the same reasons that made me run away screaming the first time.
The other [related] area of doubt is how a constructor might mix and match optional/defaulted bits with its own code - given the above you can't put the gtk_window_new() on the parameter itself, but maybe you could use say null or -1 as a sentinel [I'm sticking with the likewise-also-illegal rand() for this demo]

class window 
    integer handle 
    function window(integer r=-1) 
--      ?{"r",r,this.handle} 
        if r=-1 then r = rand(99) end if 
        this.handle = r 
--or    if r!=-1 then this.handle = r end if 
        return this 
    end function 
    procedure show() ? handle end procedure 
end class 
window w1 = new(), 
       w2 = new({rand(99)}) 
w1.show() 
w2.show() 

PS I can tell you from today's experience that errors in constructors generate the same level of helpfulness you'd expect from C++

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

Search



Quick Links

User menu

Not signed in.

Misc Menu