Page 1 of 1
Consolidate Messages
Posted: Fri Jun 03, 2011 8:57 am
by glenn52
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
Re: Consolidate Messages
Posted: Fri Jun 03, 2011 9:09 am
by SparkOut
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.
Re: Consolidate Messages
Posted: Fri Jun 03, 2011 11:55 am
by Klaus
Hi Glen,
you can also do this:
Code: Select all
on enterinfield
returninfiled
end enterinfield
But "outsourcing" the actual command(s) like SparkOut showed is the better way!
Best
Klaus
Re: Consolidate Messages
Posted: Fri Jun 03, 2011 4:44 pm
by jacque
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.
Re: Consolidate Messages
Posted: Sat Jun 04, 2011 1:51 am
by glenn52
Thanks everyone, GR8 stuff!!