Page 1 of 1

Get the names of all object type within a group

Posted: Sat Jun 21, 2014 12:37 am
by buchacho
I am trying to come up with a method to automatically get and send all the contents of different fields and store them in a database. It would be for something like storing persistent values based on who is using the program. I was thinking if I can put all the fields in a group, and get all the names of the fields within the group into a list via a livecode function, then I can automatically go through the list and put their contents into a database with columns for the username, card name, field name, and field contents. How can I do this?

Re: Get the names of all object type within a group

Posted: Sat Jun 21, 2014 12:55 am
by Simon
Hi buchacho,
Fun stuff.

Code: Select all

repeat with x = 1 to the number of fields of this cd --number of fields of group "myGroup" of this cd
put the text of fld x & cr after myVar
end repeat
Simon :D
Edit: oops
...and get all the names of the fields within the group...

Code: Select all

put the name of fld x & cr after myVar

Re: Get the names of all object type within a group

Posted: Sat Jun 21, 2014 3:13 pm
by bangkok
You could use as well custom properties, that would contain the name of the column and be used as a "flag" (to know for instance if the field must be "emptied" before to display another record)

Code: Select all

repeat with i = 1 to the number of fields of this cd
if the cDB of fld i is not empty then
---update database
end if
end repeat
My point : on your card, you might have fields (labels for instance, or fields in datagrid) that won't be meaningful for your database. Using a custom property is a good way to "discriminate".

Re: Get the names of all object type within a group

Posted: Sat Jun 21, 2014 3:41 pm
by FourthWorld
bangkok wrote:You could use as well custom properties, that would contain the name of the column and be used as a "flag" (to know for instance if the field must be "emptied" before to display another record)
I've seen a few people use a similar flag in the object name, in which label fields (those not containing record content) begin with "lbl".

In my own work, most label fields are simply named "lbl", and where I may need to address them individually (such as for handling layouts in a resizeStack handler) I'll append something meaningful after the "lbl"; for example, next to a field named "Notes" I may have a label named "lblNotes".

Either custom props or naming conventions is useful, but one thing I've found handy with using a naming convention for label fields is that when looking at a list of control names such as in the Project Browser I can readily identify the field labels.