It's a great piece of trivia!

Thanks,
Michael
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joseph J.
Strout
Sent: Tuesday, February 14, 2006 10:18 AM
To: REALbasic NUG
Subject: RE: Control Array Question

At 9:13 AM -0500 2/14/06, Michael wrote:

>Taking this a little further, if I were to create an array of push button
>control objects, is there any way to programmatically assign different
>actions to the buttons in the array?

There is, actually, though it's a bit obscure.  The PushButton class 
implements the ActionSource interface, which means that it has an 
addActionNotificationReceiver method.  This method takes, as a 
parameter, any object that implements the actionNotificationReceiver 
interface.  So you can:

1. Create a class that has "actionNotificationReceiver" among its 
interfaces.  Such a class will therefore have a PerformAction method.

2. On your new pushbutton (let's call it pb), add an instance of your 
class (let's call it thing) like so:

   pb.addActionNotificationReceiver thing

3. There's no step three!  Now, whenever somebody clicks the pb 
button, thing's PerformAction method will be called.

This isn't necessarily the best way to solve your real problem 
(another way would be to keep a dictionary that maps pushbuttons to 
some sort of action, and simply look 'me' up in the button's Action 
event and act accordingly), but it certainly is a nifty bit of RB 
trivia, wouldn't you say?

Best,
- Joe


-- 

Joe Strout  --  [EMAIL PROTECTED]
Available for custom REALbasic programming and training.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>




_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to