asynchronous messages and answer dialog

rodney tamblyn rodney at infiny.co.nz
Thu Mar 18 00:16:14 EST 2004


Be careful if you call answer from a message that is generated 
asynchronously.  For example, consider following:

on loadthepage
put "http://www.mypage.com" into myURL
load url myURL with message "loadthepagecompleted"
end loadthepage

on loadthepagecompleted
  answer "it's loaded"
end loadthepagecompleted

Now imagine what happens if the user *already* has an answer dialog 
open on the screen when loading completes and the 
'loadthepagecompleted' handler is called. Revolution will lock up when 
it tries to open the second answer dialog.  In the development 
environment you can use command + . to exit out of this situation.

The solution:

on loadthepagecompleted
    if the windows contains "answer dialog") then
     wait until not (the windows contains "answer dialog") with messages
   end if
   answer "it's loaded"
end loadthepagecompleted

You need to use 'with messages' otherwise other threads can't continue 
which we need to allow the user to respond to the dialog they already 
have open.  Interestingly (I think I've noted this before on the list) 
'there is a window "answer dialog"' will return true even if there 
isn't an answer dialog visible, whereas  'the windows' will always 
correctly return a list of the open windows.  I don't know if this is a 
bug - certainly looks like one to me.

Rodney
--
Rodney Tamblyn
44 Melville Street
Dunedin
New Zealand
+64 3 4778606
http://rodney.weblogs.com/



More information about the use-livecode mailing list