Page 1 of 1
How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 1:43 am
by sritcp
I want my program to respond only if a button is clicked (not if clicked anywhere else). Since the action of all buttons on all cards are similar, I am trying to write a mouseUp message handler at the stack level. So I need to first make sure that if the click was received by a button. I tried
If the target is a button then .....
but it doesn't seem to be legal. So, what is the property of an object that specifies it as a button, field, menu, etc. ? Or, what's another way to achieve my objective?
Thanks,
Sri.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 2:25 am
by sturgis
if word 1 of the target is "button" then...
Should work like a charm.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 3:34 am
by sritcp
Hi sturgis:
Thanks. Simple and clever solution!
By the way, if I use target instead of the target, it doesn't work (even though the dictionary says that both are equivalent for objects other than a field).
Regards,
Sri.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 11:43 am
by gpb01
sritcp wrote:Hi sturgis:
Thanks. Simple and clever solution!
By the way, if I use target instead of the target, it doesn't work (even though the dictionary says that both are equivalent for objects other than a field).
Regards,
Sri.
Is a
function so, or you use
the target or you use
target() ... with the parenthesis !
Guglielmo
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 2:12 pm
by sturgis
Yep, as Guglielmo says, check the dictionary, you can either use THE TARGET or TARGET().
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 3:22 pm
by sritcp
I was referring to the following, found in the Comments section under target keyword in the dictionary
If the target object is not a field, the target keyword reports the name of the object, just like the target function.
I found that it does not; target keyword reports nothing; the message box is blank. (The target function works, of course).
This is what I was trying to convey.
Regards,
Sri.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 3:35 pm
by sturgis
Hmm interesting.
If I put a mouseup handler into the card, then drop a button and a field onto the card
And the mouseup handler is as follows
on mouseUp
put target
end mouseUp
It works exactly as described. If I click the text field (with text in it, and with the locktext set to true) it displays the contents of the field in the msg box. If I click the button (and there is no mouseup handler in it) it displays the button name.
So the most likely answer is your field is not locked, so when yuo click it there is no mousup sent, instead the insertion point is placed at the location of the mouse click.
From the mouseup dictionary entry
The mouseUp message is sent only when the Browse tool is being used. If an unlocked field is clicked with mouse button 1 or 2, no mouseUp message is sent.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 5:53 pm
by sritcp
sturgis wrote:
.............
on mouseUp
put target
end mouseUp
It works exactly as described...........
Yes, but not if you try
put word 1 of target
I guess "word 1 of" doesn't work with
target but does with
the target.
(By the way, I tried only with a button; so the "lockedText" explanation, while valid, didn't apply in my case)
Regards,
Sri.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 6:03 pm
by sturgis
That is a bit weird, and I finally see what you're talking about.
of course for what you're trying to do using the function is a better choice either way, however to make it work as expected with the keyword rather than function you can do this
put word 1 of (target) -- force target to be completely evaluated first
Good catch, it SHOULD work as you say. I just always use target() or the target so this is a new one on me!
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 6:08 pm
by sritcp
sturgis wrote:......
put word 1 of (target) -- force target to be completely evaluated first
And it works! And, I learned something today!
Thanks,
Sri.
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 6:10 pm
by sturgis
sritcp wrote:sturgis wrote:......
put word 1 of (target) -- force target to be completely evaluated first
And it works! And, I learned something today!
Thanks,
Sri.
So did I!
Re: How do I code "If this is a button, then ..."?
Posted: Sat Jun 23, 2012 9:58 pm
by jacque
It's historical syntax dating back to HyperCard. The keyword "target" (without "the" or parentheses) refers to the text content of a field.
If you click on a field:
put target -- field text content
put the target -- "field x of stack y"