Function for returning a list of objects on a card
Bob Sneidar
bobsneidar at iotecdigital.com
Fri Jan 5 12:10:12 EST 2018
Hi all.
I put together a couple of handlers that will return all the objects on a card in the form of an array whose elements are the objects names as a return delimited list, the Long IDs as a return delimited list and an array of the properties of each object which properties are passed in a parameter. The syntax is:
put getCardObjects(pCardID, "rect,visible,owner") into aCardObjects
Set the second parameter to whatever properties you want returned. But here's the problem. The owner property returns empty. It works fine when I use the message box, but not in the script. That has to be a bug. Here is the code. If someone can verify they have the same problem and it is not an issue with my code, then I will post a bug report with a sample stack. Nothing on the QCC I can find. Put the following in a button on any card with objects:
on mouseUp pButtonNumber
put getParentCard(the long id of me) into pCardID
put getCardObjects(pCardID, "rect,visible,owner") into aCardObjects
breakpoint
end mouseUp
function getParentCard pObjectID
put offset("card id", pObjectID) into tStartChar
put char tStartChar to -1 of pObjectID into tCardID
return tCardID
end getParentCard
function getCardObjects pCardLongId, pPropList
repeat with i = 1 to the num of controls in pCardLongId
put the long id of control i of pCardLongID into tControl
put the name of tControl into tControlName
switch
case the dgProp ["control type"] of tControl is "data grid" and \
the dgProp ["control type"] of the owner of tControl is "data grid"
next repeat -- This is a control of a datagrid. We only want the datagrid itself.
break
case the dgProp ["control type"] of tControl is "data grid" and \
not (the dgProp ["control type"] of the owner of tControl is "data grid")
-- this is a datagrid
add 1 to tCounter
getObjectProps tControl, tControlName, tCounter, pPropList, aObjectData
put tControlName & cr after tObjectNames
put tControl & return after tTempObjectList
next repeat
break
end switch
-- what remains is a field, button or graphic object
add 1 to tCounter
getObjectProps tControl, tControlName, tCounter, pPropList, aObjectData
put tControlName & cr after tObjectNames
put tControl & return after tTempObjectList
end repeat
put tObjectNames into aObjects ["names"]
put tTempObjectList into aObjects ["IDs"]
put aObjectData into aObjects ["props"]
return aObjects
end getCardObjects
on getObjectProps pControl, pControlName, pIndex, pPropList, @aObjectData
repeat for each item tProp in pPropList
put the tProp of pControl into aObjectData [pIndex] [pControlName] [tProp]
end repeat
end getObjectProps
More information about the use-livecode
mailing list