References to paired controls in list
RiverSoft Art
Posts: 6,575
Hi,
I have created a list of PAIRS of controls that need to refer to each other. I have a function that creates each pair, as an example:
function CreatePair(tab) {
var cb1=new DzCheckBox(tab);
cb1.text="Foo";
var cb2=new DzCheckBox(tab);
cb2.text="Bar";
cb1.clicked.connect(function(){ cb2.checked = !cb1.checked; });
}
And then this function is called an arbitrary number of times. The problem is that cb1 and cb2 always refer to the LAST pair that was created. How can I make each pair refer to each other and no others in the list?
Post edited by RiverSoft Art on
Comments
I think fro this you may need a real function, not an in-line anonymous function, though that's a very tentative suggestion. It does look like a scope issue of some kind.
Unfortunately, I need the in-line anonymous function in order to understand which object is firing the event (if the scoping worked correctly). So it looks like I am out of luck as noone has any suggestions.
Use the "Signal to Member Function" form of connect; i.e., connect( thisObject, function ); the first argument is the object that will be bound to *this* within the scope of the function and the second argument is the function to invoke.
---
cb1.clicked.connect( cb2, function(){ this.checked = !cb1.checked; } );
cb2.clicked.connect( cb1, function(){ this.checked = !cb2.checked; } );
Yes! YES! (Dances around room). Thank you VERY MUCH Cris! That solved my problem! (Goes to dance around room some more...)