[comp.sys.next] mutiTargets

tsui@silver.bacs.indiana.edu (08/24/89)

Hello there!

    I am having difficulties figuring out how to let an object send ddifferent
messages to other objects at the same time. What I want is something like a
popUpList so that when the mouse goes down, the button send a message pop: to
the popUpList and when the mouse goes up, the popUpList send a setTitle: to the
button and at the same time notify another object that the button has changed
its title.   What I can think of is that I can rewrite setTitle: so that it 
also notifies the object I want to notify. I think it should work though I have
not tried it yet.  I feel there should be better way to set mutiple targets for
an object.  Please let me know if you have better ideas.

  Thanks in advance.

--yufeng
tsui@silver.bacs.indiana.edu

jpd00964@uxa.cso.uiuc.edu (08/25/89)

/* Written 12:17 pm  Aug 23, 1989 by tsui@silver.bacs.indiana.edu in uxa.cso.uiuc.edu:comp.sys.next */
/* ---------- "mutiTargets" ---------- */
   >I am having difficulties figuring out how to let an object send ddifferent
>messages to other objects at the same time. What I want is something like a
>popUpList so that when the mouse goes down, the button send a message pop: to
>the popUpList and when the mouse goes up, the popUpList send a setTitle: to the
>button and at the same time notify another object that the button has changed
>its title.   What I can think of is that I can rewrite setTitle: so that it 
>also notifies the object I want to notify. I think it should work though I have
>not tried it yet.  I feel there should be better way to set mutiple targets for
>an object.  Please let me know if you have better ideas.

Easy.  First, have action and target fields for all of you want to do.
id target1,target2,target3;
char action1[255],action2[255],action3[255];

// used char a[255] instead of SEL a because we need to allocate the memory

then have methods to set these

- setTarget1:anObject
{
	target1 = anObject;
	return self;
}
etc

- setAction1:(SEL)action
{
	strncpy(trncpyctaction1,
	return self;
}
etc.

Then in your method that sends everything, just call it for all you want
sequentially;
[target1 @selector(action1)];
[target2 @selector(action2)];
[target3 @selector(action3)];

This should be easily implemented.

Michael Rutman
Softmed