Weirdness Passing Messages

David Burgun dburgun at dsl.pipex.com
Thu Mar 23 09:14:53 EST 2006


Hi Mark,

The problem is that this is a General Message passing handler. The  
code I sent you was vastly simplified to demonstrate the problem, in  
reality it's a lot more difficult. This is how it should work:

ListenForMessage is called by lots of objects.
PutMessage sends to all Listening objects.

It is up to the object to use the data it's sent in a manner that  
only the Message Handler of the object can determine. For instance in  
the case in question the real code looks like this:

--
--  Script for ObjectY
--
on MessageName theMessageData
-- theMessageData = CustomProperty "|" RecordKey
   set itemDelimiter to "|"
   put item 1 of theMessageValue into myArrayName
   put item 2 of theMessageValue into myRecordKey
   set itemDelimiter to ","
   put customProperties[myArrayName] of this stack into myArray
   put  myArray[myRecordKey] into myDataRecord
   put item 1 of myDataRecord into me   --*************************
end MessageName

--
--  Script for ObjectZ
--
on MessageName theMessage,theMessageData
-- theMessageData = CustomProperty "|" RecordKey
   set itemDelimiter to "|"
   put item 1 of theMessageValue into myArrayName
   put item 2 of theMessageValue into myRecordKey
   set itemDelimiter to ","
   put customProperties[myArrayName] of this stack into myArray
   put  myArray[myRecordKey] into myDataRecord
   put item 5 of myDataRecord into me  --*************************
end MessageName

If the following is executed:

get PutMessage("MessageName","cpStackArray")

(It sends to ALL listening Objects, the object decides if it should  
do something or not and what to do if so)

The lines marked ************************ are differ in this example.  
In the case of the Real App, there are 15 fields like this, for  
instance one field is an email address. In this case the Handler  
checks to make sure it is a valid email address, and if not sets the  
text color to Red.

I am using this for all kinds of different messages with all kinds of  
different data being passed. Only the receiving object "knows" what  
to do with the data.

Thanks a Lot
All the Best
Dave

On 23 Mar 2006, at 13:56, Mark Smith wrote:

> On the other hand, given the function below, it might be more  
> efficient for the calling handler to do the work, since it already  
> knows the the long name and has the data. I mean that if a handler  
> is going to send a message to a control, along with some data, it  
> can certainly perform whatever actions are required, itself.
>
>> function PutDataIntoMe theLongName,theData
>>   do "put theData into " & theLongName
>> end PutDataIntoMe
>
>
> In your original example:
> function PutMessage theMessageID
>
> Looks up theMessageID in the Array built in ListenForMessages and  
> calls (via a "send" statement) the handler with the name  
> theMessageID at the location(s) specified in the data part of the  
> array.
>
> Since putMessage knows the location, and has the data, it can do  
> the work itself, avoiding any context issues altogether.
>
> There may be other issues I don't know about, of course, but I'm  
> sure you see what I mean.
>
> Mark




More information about the use-livecode mailing list