Identifying DataGrids
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Identifying DataGrids
Is there a function or a script that can look at all the controls on a card and identity the ones that are datagrids? I would like something that would return the just the names of any datagrids present.
Thanks,
Larry
Thanks,
Larry
Re: Identifying DataGrids
Hi Larry,
check this custom property set entry of a group:
Best
Klaus
check this custom property set entry of a group:
Code: Select all
...
if the dgProps["control type"] of grp "xyz" = "Data Grid" then
answer "You guess..."
end if
...
Klaus
Re: Identifying DataGrids
Thanks Klaus,
You came to the rescue once again. I spliced that into the code I was working on and it did the job.
Larry
You came to the rescue once again. I spliced that into the code I was working on and it did the job.
Larry
Re: Identifying DataGrids
Building my applications, I often use Trevor's data grid "DataGrid".
And also often, I need to know types and specifics of my controls on my card without polluting the returning lists with all the controls the data grids contain. For this reason, I just created a new function that might help others and is a bit different from those posted here before. It just took me about one hour (this is also why I love LiveCode -- you can do things amazingly fast).
Of course, this function can easily be modified to just return 'true' or 'false' if just to know whether a control is part of a data grid -- or just do the opposite and return only those controls that are part of a data grid (while that is pretty easy to do otherwise).
Function: filterWithoutDGControls ( pType , pIncludeFlag )
This function is called "filterWithoutDGControls " and returns the names of specific or all types of controls optionally including the names of the data grids present if specified in parameter "pIncludeFlag" setting this flag to "true".
Parameter 1: pType: The name of the control type ( 'control' | 'field' | 'button' ... etc.). It can be empty.
Parameter 2: pIncludeFlag: If set to "'true' then also the name/s of the data grid themselves are included in the returning control list. It can be empty.
Maybe this helps. I am sure any function can be improved. Suggestions are welcome. Ideally, a control that belongs to a data grid already has a property that tells us and therefore more easily can be filtered. We can also build custom properties ourselves (using such function) to define the opposite that the control is not part of a data grid. But the function here is trying to be as general and applicable as possible.
Best wishes to all ... Roland (golife)
And also often, I need to know types and specifics of my controls on my card without polluting the returning lists with all the controls the data grids contain. For this reason, I just created a new function that might help others and is a bit different from those posted here before. It just took me about one hour (this is also why I love LiveCode -- you can do things amazingly fast).
Of course, this function can easily be modified to just return 'true' or 'false' if just to know whether a control is part of a data grid -- or just do the opposite and return only those controls that are part of a data grid (while that is pretty easy to do otherwise).
Function: filterWithoutDGControls ( pType , pIncludeFlag )
This function is called "filterWithoutDGControls " and returns the names of specific or all types of controls optionally including the names of the data grids present if specified in parameter "pIncludeFlag" setting this flag to "true".
Parameter 1: pType: The name of the control type ( 'control' | 'field' | 'button' ... etc.). It can be empty.
Parameter 2: pIncludeFlag: If set to "'true' then also the name/s of the data grid themselves are included in the returning control list. It can be empty.
Code: Select all
function filterWithoutDGControls pType,pIncludeFlag
## Returns controls of type pType or any controls that are not part of a datagrid
// Declaring local variables (I ALWAYS do and recommend strongly)
local tOut -- Result string, my standard name for returning lists
local tOut2 -- used here for additional datagrid names
local tID -- a datagrid id
local tIDList -- a list of words that are datagrid id's
local tFlag -- if true then also the names of datagrids themselves are returned
// Default values and validation
if pType = "?" then return "put filterDGControls (pType,pIncludeFlag) --> filter datagrid controls. pType = control name, pIncludeFlag = true or false"
if pType is empty then
put "control" into pType -- Search for all controls if no parameter
put "true" into pIncludeFlag
end if
// Start filter routine
repeat with i = 1 to the number of controls
// Filter types of controls
if word 1 of the name of control i is not pType AND pType is not "control" then
next repeat
end if
// Check if control or type pType is part of a datagrid
put false into tFlag
-- dgProps["data grid"] informs of a group is a datagrid. If empty then it is not.
if the dgProps["control type"] of control i is "Data Grid" then
put the id of control i &space after tIDList
next repeat
else
repeat for each word tID in tIDList
if tID is in the long id of control i then
put true into tFlag
end if
end repeat
if tFlag is false then
put the name of control i &CR after tOut
else
next repeat
end if
end if
end repeat
delete last char of tOut -- the CR character
// If we want to list also the datagrids without their owned controls
if pIncludeFlag is true then
if pType is "group" OR pType is "control" AND tIDList is not empty then
repeat for each word tID in tIDLIst
if there is a control id tID then -- double check
put the name of control id tID &CR after tOut2
end if
end repeat
end if
delete last char of tOut2
put tOut&CR&tOut2 into tOut
end if
sort tOut
return tOut
end filterWithoutDGControls
Best wishes to all ... Roland (golife)
Re: Identifying DataGrids
Hi Roland (golife), thank you very much for sharing this. It served as the basis for creating my own version of its function.
Code: Select all
function filterWithoutDGControls pLongId, pType, pIncludeFlag
## Returns controls of type pType or any controls that are not part of a datagrid
local tChildControlIDs, tName, tType, tRresult
if there is not a pLongId or the word 1 of pLongId is not in "stack,card,group,control,widget,button,field,scrollbar,image,player,graphic"
then put the long id of this card into pLongId
if pType is not in "stack,card,group,control,widget,button,field,scrollbar,image,player,graphic"
then put "control" into pType
put the childControlIDs of pLongId into tChildControlIDs
repeat for each line tControlID in tChildControlIDs
put the name of control id tControlID of pLongId into tName
put the word 1 of tName into tType
if pType is not "control" and tType is not pType then next repeat
if tType is "card" or tType is "group" then
if pIncludeFlag is true then
put filterWithoutDGControls(the long id of control id tControlID of pLongId, pType, pIncludeFlag) & cr after tRresult
else if the dgProps["control type"] of control id tControlID of pLongId is empty then
put filterWithoutDGControls(the long id of control id tControlID of pLongId, pType, pIncludeFlag) & cr after tRresult
end if
end if
put tName & cr after tRresult
-- Or
-- put the long id of control id tControlID of pLongId & cr after tRresult
-- put the abbreviated id of control id tControlID of pLongId & cr after tRresult
end repeat
delete last char of tRresult
sort lines of tRresult
return tRresult
end filterWithoutDGControls
Re: Identifying DataGrids
@ andresdt
That is very enjoyable to see...
Thank you. I will think about it and if there is something worthwhile coming to mind, I will post.
Have a nice spring day.
Roland (golife)
That is very enjoyable to see...
Thank you. I will think about it and if there is something worthwhile coming to mind, I will post.
Have a nice spring day.
Roland (golife)
Re: Identifying DataGrids
@ andresdt
Your function is clever. I need to always turbo-charge my brain when it comes to recursive functions. Actually, I like to use it for extending it to something much more. I will post this separately when finished.
I was not currently aware of the LCS functions "the childControlIDs' and "the childControlNames', long ago that I used them and had forgotten them.
Regards and thanks
Roland (golife)
Your function is clever. I need to always turbo-charge my brain when it comes to recursive functions. Actually, I like to use it for extending it to something much more. I will post this separately when finished.
I was not currently aware of the LCS functions "the childControlIDs' and "the childControlNames', long ago that I used them and had forgotten them.
- I added a little hack to your function as it returns some empty values when supplying specific control types. And it already working in my private library 'rhLib.rev'.
- The lists with control names 'tObjects' and' tTypes' are defined in the local variable definition and could be provided also as script variables or parameters.
- The little typo in 'tRresult' was corrected. Now it is 'tResult'.
- I added long names and need long id's mostly for the result. Which result to expect could also be defined in the parameters, even though too many parameters are ugly. I have to think about how to make this straight-forward without having to look up how to define.
- Also, I added a "help" return value using "?" which I started applying to my functions recently. Providing a question mark returns a brief information about the function itself.
- Some small code documentation add-ons
Code: Select all
function filterWithoutDGControls pLongId, pType, pIncludeFlag
## Returns controls of type pType or any controls that are not part of a datagrid
# Type: Function (recursive)
# Link: https://forums.livecode.com/viewtopic.php?f=8&t=32982&p=203950#p203950
# Author: Forum User 'andresdt'
# Help: Supply "?" as a parameter
# Location: rhLib.rev
# Dependencies: None
# Last version: 2021-03-31 19:00 -- User 'golife' added 'hack' to not receive added empty lines the the result.
# Ideas: Extend the function for a general getInfo() function
// Help
if "pLongID" is "?" then return "filterWithoutDGControls pLongId, pType, pIncludeFlag. "&\
"Empty params: The current card id is used and all control names are returned without the DG Data Grid controls."
// Local variables
local temp -- just an intermediate var -- hack
local tChildControlIDs
local tName
local tType
local tResult
local tObjects = "stack,card,group,control,widget,button,field,scrollbar,image,player,graphic"
local tTypes = "stack,card,group,control,widget,button,field,scrollbar,image,player,graphic"
// If pointer is not defined then use current card id or fall back to my own lib stack
if pLongId is empty or there is not a pLongID OR word 1 of pLongID is not in tObjects then
if the short name of this stack is "rhLib" then
put field "longCardID" into pLongID
else
put the long id of this card into pLongID
end if
end if
// If not filtered by object type then use any object/control type
if pType is not in tTypes then put "control" into pType
put the childControlIDs of pLongId into tChildControlIDs
repeat for each line tControlID in tChildControlIDs
put the name of control id tControlID of pLongId into tName
put the word 1 of tName into tType
if pType is not "control" and tType is not pType then next repeat
if tType is "card" or tType is "group" then
if pIncludeFlag is true then
put filterWithoutDGControls(the long id of control id tControlID of pLongId, pType, pIncludeFlag) into temp
if temp is not empty then
put temp & cr after tResult
end if
else if the dgProps["control type"] of control id tControlID of pLongId is empty then
put filterWithoutDGControls(the long id of control id tControlID of pLongId, pType, pIncludeFlag) into temp
if temp is not empty then
put temp & cr after tResult
end if
end if
end if
--put tName & cr after tResult
-- Or
-- put the long name of control id tControlID of pLongId & cr after tResult
put the long id of control id tControlID of pLongId & cr after tResult
-- put the abbreviated id of control id tControlID of pLongId & cr after tResult
end repeat
delete last char of tResult
sort lines of tResult
return tResult
end filterWithoutDGControls
Roland (golife)