Consolidate Messages

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn52
Posts: 25
Joined: Mon May 02, 2011 1:34 pm
Contact:

Consolidate Messages

Post by glenn52 » Fri Jun 03, 2011 8:57 am

I am looking to eliminate the number of message handlers.
The example I show here is used because of the similar functions of the returnInField and enterInField handlers
In psuedo terms, is there a way to instruct enterInField to "see returnInField above"

on returnInField
doThis
doThat
doSomethingElse
end returnInField

on enterInField
doThis
doThat
doSomethingElse
end enterInField

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Consolidate Messages

Post by SparkOut » Fri Jun 03, 2011 9:09 am

You can go to making another command that you maintain only once, and refer to it whenever, as in

Code: Select all

on returnInField
    doEnterOrReturnInFieldHandler
end returnInField

on enterInField
    doEnterOrReturnInFieldHandler
end enterInField

on doEnterOrReturnInFieldHandler
    doThis
    doThat
    doSomethingElse
end doEnterOrReturnInFieldHandler
You can go further with this approach and make generic modular handlers that you can pass parameters and have them react in different ways according to the way they were called, but still maintain only one code segment.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Consolidate Messages

Post by Klaus » Fri Jun 03, 2011 11:55 am

Hi Glen,

you can also do this:

Code: Select all

on enterinfield
  returninfiled
end enterinfield
:D

But "outsourcing" the actual command(s) like SparkOut showed is the better way!

Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Consolidate Messages

Post by jacque » Fri Jun 03, 2011 4:44 pm

Not specifically what you asked, but my general rule of thumb is that if code occurs only once, I put it inline in a handler. If code needs to happen in more than one place, I move it to its own handler or function and then call that from wherever it's needed (like SparkOut did.) You were smart to ask about it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

glenn52
Posts: 25
Joined: Mon May 02, 2011 1:34 pm
Contact:

Re: Consolidate Messages

Post by glenn52 » Sat Jun 04, 2011 1:51 am

Thanks everyone, GR8 stuff!!

Post Reply