Advice on Messaging System

David Burgun dburgun at dsl.pipex.com
Tue Dec 13 08:26:32 EST 2005


Hi All,

I have a problem that I have solved, but wondering if anyone on this 
list could think of a better/faster way of doing the same thing.

I have a number of Stacks then can be opened or closed under user 
control, each stack can generate an "Event" or "Message". One such 
message is "PrefsLanguage" which is generated when the user selects a 
new new language in the Preferences Window. The messange is sent to 
all objects that are "Listening" for the message.

The code looks like this.

In the Script for whichever controls need to know that language has 
changed (in any stack), this handler is called from the preOpenStack 
handler:

on ControlInitialize
get ListenForMessage("PrefsLanguage","ControlMessageHandler",the long 
name of me)
end ControlInitialize

--
--  This Handler gets called when a "PrefsLanguage" Message is Generated
--
on ControlMessageHandler(theMessageKey,theMessageData)
-
-  Change the text of this control to the language contained in 
"theMessageData"
-
end ControlMessageHandler

The above code is placed in all objects that want to receive the message.




In the Prefs Stack, in the control that switches languages:

get PutMessage("PrefsLanguage",theNewLanguage)

The message gets send to all Objects that are lintening for the 
"PrefsLanguage" message (including objects on the same stack).

At present I represent this using a number of arrays which are 
dynamically created (e.g. their names are built dynamically), but it 
seems quite slow.

Does anyone know of a better way to do this? Any ideas or suggestions 
greatly appreciated.

Thanks a lot
All the Best
Dave









More information about the use-livecode mailing list