setProp and Lock messages

Mark Schonewille m.schonewille at economy-x-talk.com
Sat Dec 3 13:14:22 EST 2011


Hi Todd,

I understand your problem now. I think it is up to the programmer to be careful and accurate. The lock messages command exists exactly for preventing messages from being sent. You just have to make sure that you don't lock messages in a handler without unlocking them while you should. Sometimes you might want to lock messages before setting a property and sometimes you don't. It is your task do make the right decision and to remember and lock messages commands.

Keep in mind that messages are locked until the originating handler finished running. The lock messages command doesn't persist forever, so this one thing less to worry about.

If you have a really complicated handler, then there are ways to make sure that messages are not locked, for example

repeat until not the lockMessages
  unlock messages
end repeat

I hope this helps.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/1bq Start selling Color Converter today. 20% commission!

On 3 dec 2011, at 18:35, Todd Geist wrote:

> Hi Mark
> 
> Thank you for taking the time to respond. Perhaps I didn't ask the question
> correctly, but as far as I can tell your example does address the question
> I was asking.
> 
> 
> On Sat, Dec 3, 2011 at 9:08 AM, Mark Schonewille <
> m.schonewille at economy-x-talk.com> wrote:
> 
>> The example I gave you in my previous e-mail works.
> 
> 
> 
> Take a look at this example.
> 
> On doSomething
> 
>   lock messages
> 
>   set the cProp of me to 3
> 
> end doSomething
> 
> 
> 
> setProp cProp x
> 
>   lock messages
> 
> 
> 
>   if x = "a" then
> 
>      set cProp of the target to x
> 
>   else if x = "b" then
> 
>      set the cProp of the target to x
> 
>   end if
> 
> 
> 
> end cProp
> 
> 
> I have written a setProp to only handle accept certain values, ("a" and "b"
> ).  The DoSomething handler represents  "Some other code" that attempts to
> set the property.  Since it has set locked messages, the setProp is ignored
> and values other than a and b can be set.
> 
> That is what I am talking about.
> 
> This seems to me to be a pretty big problem.  How can I ever be sure that
> setProp and GetProp handlers will actually be used.  I may not have control
> over all the code and there might be a lock messages somewhere up the chain.
> 
> Todd






More information about the use-livecode mailing list