dunbarx wrote:1- Doesn't the field that invokes the handler know who it is? I am being flip; maybe I do not understand the question.
Hi Craig, perfectly legitimate question. Consider the situation where a popup menu performs some functions on the field (add, edit, delete). You can "hard code" the name of the field into the popup menu code, but then it needs to be rewritten for every field that uses the popup. Better if you could "pass the name" of the field to the popup and then have it operate on that information... makes it more generic (actually, this is a whole area I've decided to try and get a handle on in LC which is how do you write generic code). So, for example, if the popup option was "delete" and the mouse is placed over a particular word, phrase or item in a field (or list field) then currently I have code that is written as:
case "Delete"
put the cselectedline of fld "Scrolling List Field" into x -- the line number
put line x of fld "Scrolling List Field" into temp
put "Delete" && temp && "from field Scrolling List Field?" into tprompt
answer warning tprompt with "Yes" or "No"
if it is "Yes" then
delete line x of fld "Scrolling List Field"
end if
break
And you'll recognize that cselectedline is custom property in the scrolling list field that identifies which line the user was selecting to delete. In this case we are using a custom property of the field to id the line which works fine.... IF you know the field name. You can't "pass" the field name in the same way using a custom property. And, to be completely generic, the calling field should not stuff the field name into a custom property of the pop-up menu button, because to do that would require hard coding the button name into the field script... hardly generic code.
What ideally I want to write is something like:
case "Delete"
put the cselectedline of fld gfieldname into x -- the line number
put line x of fld gfieldname into temp
put "Delete" && temp && "from" && gfieldname && "?" into tprompt
answer warning tprompt with "Yes" or "No"
if it is "Yes" then
delete line x of fld gfieldname
end if
break
So that the code can operate on any field that calls it. And, as you can see, I am currently doing that using a global variable gfieldname. Now, the downside to a global variable, of course, is that both the calling field and the popup menu have to know about the global variable and each needs to initialize it. Hardly generic. But, you've provide the perfect solution which is the answer to my second question... I had gotten as far as thinking that there probably was a way for these two objects to know about each other in LC if they were in the same group, but I could not figure out what the command (in this case property) was... and its:
2- Check out the "owner" in the dictionary.
Perfect. Now I can rewrite the code as:
case "Delete"
put the short owner of me into tgroup -- gets the group name (owner) of this menu
put the cfieldname of grp tgroup into tfieldname -- get the field name that called the menu (haven't tested this yet)
put the cselectedline of fld tfieldname into x -- the line number
put line x of fld tfieldname into temp
put "Delete" && temp && "from" && tfieldname && "?" into tprompt
answer warning tprompt with "Yes" or "No"
if it is "Yes" then
delete line x of fld tfieldname
end if
break
Now the field and the popup can interact and neither needs to know the name of the other. Put another way, if you place this group on a card you can call the field and the popup menu anything you like and the code will still work fine.
Or so the theory goes

I haven't tested any of this yet so I am hoping it works!!!
dunbarx wrote:What properties did you have in mind?
In this case the properties would be the information that the pop-up needs to operate on: the field name and the item in the field. Currently I call the popup like this:
if theButton is 3 then -- right button
-- set a custom property of this field to word 2 of the selectedline
-- and set the gfieldname to the name of this field
-- the last two are needed by the "Popup" menu
set the cselectedline of me to theline
put the short name of me into gfieldname -- for passing to the popup menu (using global var)
popup button "Popup Menu"
Now I'll be able to change that so the field name is a custom property of the group (I think?)
put the short owner of me into tgroup
set the cfieldname of grp tgroup to the short name of me -- instead of a global variable
popup button "Popup Menu"
and get it at the other end (the menu end) using the code I wrote above. I'm just writing this as I prepare to rush off to work but I get the general idea (and will worry about the syntax later).
dunbarx wrote:Do you mean share a script, as if the behavior (look up "behavior") of each object was set to effect that functionality?
I haven't looked into behaviours but will take a look as well. Thanks Craig for your many suggestions. I think the "owner" property is the key,
Cheers,
-- Mark