From: Albert Wagner Date: 2001-07-03T09:13:49+09:00 Subject: [ruby-talk:17171] Re: FXRuby: How to forward a message? That's great, Barry. Thank you. On Monday 02 July 2001 12:09, you wrote: > > -----Original Message----- > > From: Albert Wagner [mailto:alwagner@tcac.net] > > Sent: Friday, June 29, 2001 6:12 PM > > To: ruby-talk@ruby-lang.org > > Subject: [ruby-talk:17067] FXRuby: How to forward a message? > > > > > > Do any of you FOX users know how to forward a message? How to use > > FXDelegator? > > Hi Albert, > I don't have any experience using FXDelegator, but I just found this old > foxgui-users > e-mail from Lyle. > > Barry > *************************************************************** > > > I am doing something like below using FXRuby > > > > FXButton.new(..., getMyTarget(),ID_MyOwn,...) > > > > getMyTarget() returns the widget that will be different ones > > during runtime. > > Then I realized that FOX will map to the object it first gets and can > > not change it during runtime unless using "setTarget". I have many > > buttons that need to send message to newly created widget during runtime. > > Having to setTarget in several handlers for all these buttons is awkward. > > I have been using GTK and the callback mechanism make it trivial to do > > this. > > Would it be possible to trick FXRuby to do dynamic binding? > > Ted, > > I think the FXDelegator class is what you're looking for. An FXDelegator is > an object that forwards all incoming messages to some other object. Let's > say you have five different buttons that should send their messages to the > same object -- but that target object is going to change at runtime. You'd > do something like this: > > # Initially the delegator will send all its messages > # to the object "initialTarget" > delegator = FXDelegator.new > delegator.setDelegate(initialTarget) > > # Each of these buttons will send their messages to > # the delegator, which in turn will forward those > # messages to "initialTarget" > btn1 = FXButton.new(p, txt, icn, delegator, ID_BUTTON1, ...) > btn2 = FXButton.new(p, txt, icn, delegator, ID_BUTTON2, ...) > btn3 = FXButton.new(p, txt, icn, delegator, ID_BUTTON3, ...) > btn4 = FXButton.new(p, txt, icn, delegator, ID_BUTTON4, ...) > btn5 = FXButton.new(p, txt, icn, delegator, ID_BUTTON5, ...) > > ... time passes ... > > # We now want those five buttons' messages to go to "newTarget" > newTarget = FXSomething.new(...) > delegator.setDelegate(newTarget) > > Hope this helps, > > Lyle > > > _______________________________________________ > Foxgui-users mailing list > Foxgui-users@lists.sourceforge.net > http://lists.sourceforge.net/lists/listinfo/foxgui-users