Extracting a reference to a stack
Peter Haworth
pete at lcsql.com
Sat Aug 8 13:45:56 EDT 2015
I do it like this
function stackOfObject pobject
local tObject
put pobject into tObject
repeat
if word 1 of tObject is "stack" then
return tObject
end if
On Sat, Aug 8, 2015 at 10:31 AM Peter M. Brigham <pmbrig at gmail.com> wrote:
> OK, Here's a revision:
>
> function ownerStack pObjLongID
> -- returns the name of the stack immediately containing pObjLongID
> -- by Peter M. Brigham, pmbrig at gmail.com — freeware
> -- tags: control
> -- requires getprop robustName
>
> replace " of " with cr in pObjLongID
> put lineoffset(cr & "stack ",cr & pObjLongID) into stLine
> put line stLine to -1 of pObjLongID into stName
> replace cr with " of " in stName
> return stName
> end ownerStack
>
> -- Peter
>
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
>
>
> On Aug 8, 2015, at 10:45 AM, David Bovill wrote:
>
> > There was a recent feature added to the language that would help - maybe
> it
> > was something to do with the owner....
> >
> > I have a similarly convoluted function and getprop - one of the issues is
> > that if you want the long name of the stack the control is part of - this
> > could be a mainstack or a substack - so to get "the stack on which the
> > control is placed" has always been a bit of a pain...
> >
> > On 8 August 2015 at 15:16, Peter M. Brigham <pmbrig at gmail.com> wrote:
> >
> >> Here's a quick solution:
> >>
> >> function ownerStack pObjLongID
> >> replace " of " with numtochar(8) in pObjLongID
> >> set the itemdel to numtochar(8)
> >> return item -1 of pObjLongID
> >> end ownerStack
> >>
> >> A more general solution is what I use in my library. The getItem()
> >> function is so useful that I use it *everywhere*.
> >>
> >> function ownerStack pObjLongID
> >> -- returns the name of the stack containing pObjLongID
> >> -- by Peter M. Brigham, pmbrig at gmail.com — freeware
> >> -- requires getItem(), getDelimiters()
> >>
> >> put getItem(pObjLongID,-1," of ") into tStack
> >> put the name of tStack into stackName
> >> return stackName
> >> end ownerStack
> >>
> >> function getItem pContainer, pIndex, pDelim
> >> -- returns item # pIndex of pContainer, given itemdelimiter = pDelim
> >> -- could just "get item pIndex of pContainer" in the calling handler
> but
> >> -- then have to set and restore the itemDelimiter, so this is less
> >> hassle
> >> -- for instance, the following returns the filename from the filepath:
> >> -- put getItem(tPath,-1,"/") into tFileName
> >> -- defaults to pDelim = tab
> >> -- allows pIndex to be a range, eg "3-5"
> >> -- in that case enclose the range in quotes
> >> -- also allows pDelim to be a string of characters
> >> -- so you could do this:
> >> -- getItem("a//b//c//d//e//f",4,"//") -> d
> >> -- or:
> >> -- getItem("a or b or c or d or e or f","3-5"," or ") -> c or d
> >> or e
> >> -- which expands the possibilities for use enormously
> >> -- by Peter M. Brigham, pmbrig at gmail.com — freeware
> >> -- requires getDelimiters()
> >>
> >> -- first, if pDelim is a string then get a delimiter that is not found
> >> -- in pContainer and use it in place of pDelim
> >> if pDelim = empty then put tab into pDelim
> >> if len(pDelim) > 1 then
> >> put getDelimiters(pContainer) into tempDel
> >> if tempDel begins with "Error" then
> >> return "Error in getDelimiters()"
> >> end if
> >> replace pDelim with tempDel in pContainer
> >> else
> >> put pDelim into tempDel
> >> end if
> >>
> >> -- now parse pIndex to take care of ranges and negative values
> >> -- and get the item(s) requested
> >> put offset("-",pIndex) into dashPos
> >> set the itemdelimiter to tempDel
> >> if dashPos > 1 then
> >> -- don't catch if pIndex is something like -1, -2, etc
> >> put char 1 to dashPos-1 of pIndex into tStart
> >> put char dashPos+1 to -1 of pIndex into tEnd
> >> put item tStart to tEnd of pContainer into theItem
> >> replace tempDel with pDelim in theItem
> >> else
> >> put item pIndex of pContainer into theItem
> >> end if
> >> return theItem
> >> end getItem
> >>
> >> function getDelimiters pText, nbr
> >> -- returns a cr-delimited list of <nbr> characters
> >> -- not found in the variable pText
> >> -- use for delimiters for, eg, parsing text files, manipulating
> arrays,
> >> etc.
> >> -- usage: put getDelimiters(pText,2) into tDelims
> >> -- if tDelims begins with "Error" then exit to top -- or
> whatever
> >> -- put line 1 of tDelims into lineDivider
> >> -- put line 2 of tDelims into itemDivider
> >> -- etc.
> >> -- by Peter M. Brigham, pmbrig at gmail.com — freeware
> >>
> >> if pText = empty then return "Error: no text specified."
> >> if nbr = empty then put 1 into nbr -- default 1 delimiter
> >> put "2,3,4,5,6,7,8,16,17,18,19,20,21,22,23,24,25,26" into baseList
> >> -- low ASCII values, excluding CR, LF, tab, etc.
> >> put the number of items of baseList into maxNbr
> >> if nbr > maxNbr then return "Error: max" && maxNbr && "delimiters."
> >> repeat with tCount = 1 to nbr
> >> put true into failed
> >> repeat with i = 1 to the number of items of baseList
> >> put item i of baseList into testNbr
> >> put numtochar(testNbr) into testChar
> >> if testChar is not in pText then
> >> -- found one, store and get next delim
> >> put false into failed
> >> put testChar into line tCount of delimList
> >> exit repeat
> >> end if
> >> end repeat
> >> if failed then
> >> if tCount = 0 then
> >> return "Error: cannot get any delimiters."
> >> else if tCount = 1 then
> >> return "Error: can only get one delimiter."
> >> else
> >> return "Error: can only get" && tCount && "delimiters."
> >> end if
> >> end if
> >> delete item i of baseList
> >> end repeat
> >> return delimList
> >> end getDelimiters
> >>
> >>
> >> On Aug 8, 2015, at 8:23 AM, David Bovill wrote:
> >>
> >>> Given the long id of a control - how do I extract the reference to the
> >>> stack ti belongs to? I have a function that i have used since the dawn
> of
> >>> time for this - but I recall seeing a new chunk / target / reference
> >>> feature of Livecode in the last year that makes this easier. Did I
> >> imagine
> >>> it?
> >>> _______________________________________________
> >>> use-livecode mailing list
> >>> use-livecode at 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 at 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 at 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
More information about the use-livecode
mailing list