Thanks Martin. That does indeed work (might need tweaking for some more
complex cases).
However, it goes through all controls on the card - the same effect is
achieved without the performance risk using the childControlIDs, as in
function idOfChild pLongID, pShortName
repeat for each line L in the childControlIDs of pLongID
if the short name of control ID L = pShortName then return the
long id of control ID L
end repeat
end idOfChild
I'm currently using that - but I'm convinced by Richard and Dr Seuss
that I'm on the wrong path and will try a redesign.
Alex.
On 28/07/2020 04:04, Martin Koob wrote:
Hi Alex
You could use the owner of the control in conjunction with the name of
the control to distinguish between the two graphic’s named ‘R’.
I did that for the simple case in your example but may not work
with something more complex.
I created a stack with the same hierarchy of graphics and groups and
using the following scripts in a button I placed on the card I can
distinguish between graphic A - R and B - R.
*
*
*on* mouseup
*ask*“enter owner name/control name/control colour"
*put* it into tResponse
*set*theitemdelimiterto"/"
*put*item1of tResponse into tOwner
*put*item2of tResponse into tControl
*put*item3of tResponse into tControlColour
*put* findTargetControl(tOwner, tControl) into tTargetControl
*set*thebackgroundcolorofcontrol tTargetControl
of*group*"A"to tControlColour
*end* mouseup
*function* findTargetControl pOwner, pControl
*put*thenumberofcontrolsof*group*"A"into tIndex
*repeat* with tControl = 1to tIndex
*if* theshortnameofcontrol tControl of*group*"A" = pControl *then*
*if* theshortnameoftheownerofcontrol tControl of*group*"A" = pOwner *then*
*exit* *repeat*
*end* *if*
*end* *if*
*end* *repeat*
*return* tControl
*end* findTargetControl
Martin Koob
On Jul 27, 2020, at 8:47 PM, Alex Tweedly via use-livecode
<use-livecode@lists.runrev.com
<mailto:use-livecode@lists.runrev.com>> wrote:
On 27/07/2020 21:26, Curry Kenworthy via use-livecode wrote:
Use unambiguous SHORT names!
Thanks, but ...
Yes, using unambiguous SHORT names solves this naming problem, but
introduces other problems. In particular, this group script should
(probably) be a behaviour script, since the group will be
instantiated multiple times and will in the future need updating for
enhancements or even (Heaven forfend!) bug fixes.
Using unambiguous short names prevents behaviour scripts that
references child controls completely, and even if I simply used
normal scripts which were replicated for each instance, I'd still
need to go through the script to change all the references to the
child control names (a pain, and source of possible future errors).
For now, I'm caching the IDs of the direct child controls in
script-local variables in each instance of the group. If I find a
name-based way that works reliably and allows behaviour scripts, I'll
change - but this method works.
I'll have this group ready for release soon (or soon-ish) so y'all'll
be able to see how it turned out :-)
Thanks again everyone,
Alex.
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com <mailto:use-livecode@lists.runrev.com>
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode