The Long Owner (was Re: "the effective visibility")

Ken Ray kray at sonsothunder.com
Sat Aug 9 14:54:33 EDT 2008


> AFAIK the owner's property is reliable as long as you don't try to
> code some expression using the owner of the owner of the owner of
> tObj...
> Using this form, I have got unexpected results.
> On the other hand, the long owner is the long name of the owner and I
> would prefer if it was the long ID:
> There are cases where you have to 'get' the long ID of the owner of
> tObj to be safe...
> I am thinking of hundreds of groups created on the fly for instance.

Here's the skinny (after lots of time and trial)... suppose you have this
set of objects on the card:

Group "MainGroup"  -- label "MainGroup 1"
    Group "MyGroup"  -- label "Group 1"
       Button "MyButton"

Group "MainGroup"  -- label "MainGroup 2"
    Group "MyGroup"  -- label "Group 2"
       Button "MyButton"

And you have code in the buttons that simply say:

  put the label of the long owner of me

This won't work - in both cases you get "Group 1" - this is because "the
long owner" retrieves a *named* object:

   group "MyGroup" of group "MainGroup" of card ...

which matches *both* groups. This happens no matter what property you try to
get of "the long owner". And once you have the *wrong* "long owner", trying
to get the "long owner" of *it* messes up as well, so:

  put the label of the long owner of the long owner of me

Will always give you "MainGroup 1".

So if you can't get away with uniquely naming your group objects for some
reason, the only thing you can do is basically what David and Bernard
pointed out - parse the long id of the target. Here's what I use:

function stsLongOwnerID pObjID,pOpt_NumLevels
  if pOpt_NumLevels = "" then put 1 into tNum
  else put pOpt_NumLevels into tNum
  if word ((4*tNum)+1) of pObjID is among the items of "group,card" then
    delete word 1 to (4*tNum) of pObjID
  end if
  return pObjID
end stsLongOwnerID

This allows me to do either:

  put stsLongOwnerID(stsLongOwnerID(the long id of me))

OR

  put stsLongOwnerID(the long id of me,2)

to get the same result.

I wish that the language was extended to be able to add "ownerID" in
addition to "owner" so you could do:

  put the long ownerID of the long ownerID of me
  
to get an accurate result, but that's not in there yet...


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list