Gotchya with sigslot library

Andrew Tetlaw <[email protected]>
Newsgroups gmane.comp.windows.devel.netwindows
Message-ID <OF547BF93F.F2BCEA50-ON4A256D97.00260ACB-4A256D97.00274BC1@bvn.com.au>
Hello all,

I'm using the sigslots library separately in a project and I came across 
this gotchya. Now, this is probably going to seem like common sense to you 
guys, but I'm just a beginner with sigslots so bear with me.

I've discovered you cannot connect to a slot that is a function defined as 
a prototype function of the slot object if more than one of that type of 
object exists.

This is because, as a prototype function the FP is identical for all 
objects of that type and the emitWithArgs function will apply the first 
connArr[fp] it finds which may or may not be the correct slot object.

Phew! Took a day to find that one.

Example:
===============
I have 2 tabRow objects each with 3 tab objects. A tab object has a 
'click' signal connected to its parent row's 'activateTab' slot. 
'activateTab' is defined as a prototype function of the tabRow class.

Problem is: When row #2's tabs are clicked row #1 get's the signal. This 
is because row #1 is instantiated first and thus it gets added to connArr 
first. Then when the tab does an emitWithArgs, if finds row #1's fp and 
finds that it matches every time.

So if defined like this there are problems:

tabRow.prototype.activateTab = function() {}

But change it to this and it works fine:

function tabRow() {
        ...
        this.activateTab = function() {}
}
===============

As I said it's probably common sense to you guys, but might be a common 
gotchya for punters like me. the class.prototype method of making 
object.methods is quite common (useful for inheritance).

Cheers,
Andrew Tetlaw

Bligh Voller Nield
http://www.bvn.com.au
p: (07) 3251 5778
f: (07) 3852 2544


<font face="Arial, Helvetica, sans-serif" size="2">
<b>

Please Also Note
</b>This document, including attachments, is only intended for the addressees and may contain privileged or confidential information. Unauthorised use, copying or distribution of the document or any part of its contents, is prohibited. If you receive this Email in error please notify us by return Email or telephone. We will reimburse you for any reasonable expenses incurred in meeting this request.</font> 


_______________________________________________
The netWindows developers list: [email protected]
http://netwindows.org/mailman/listinfo/devel_netwindows.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.