Hi all. 

I wanted to share what may be a useful command for filling in data and setting 
controls on a card. This assumes you have an array whose key names “match” 
control names with the following rules:

Fields you want filled must begin with “fld”
Checkboxes you want hilited must begin with “btn” and the value must be true or 
false
Menu style buttons you want to set must begin with “mnu” and the value must be 
one of the choices for the menu
Radio button groups must begin with “rdo” and the value must be one of the 
button names in the group
Datagrids you want populated can be named as you please, and the value must be 
an encoded array

For instance a field named “fldCustomerName” will be populated with the value 
in key theData[“customername”]. A field simply named “customername” will be 
ignored. I use this convention because this is how I distinguish positively the 
fields I want populated and the ones I want to leave alone. Also, it’s how I 
determine the method for populating the control. 

Since I use sqlYoga a BUNCH, the data I return from query calls is an numbered 
array of arrays representing the returned records. Since I sometimes store 
whole data grid arrays in SQL, I have to encode them first, hence the need to 
arrayEncode them first. If I pass a single array record from the numbered array 
I get from sqlYoga queries, this command will populate any form that uses this 
naming convention. 

However, you can build your own array and it will work fine. 

I hope you like it. DISCLAIMER: I have not completely debugged it yet, I just 
wrote it so use with caution. 

Bob



on populate theData
   if theData is not an array then exit populate
   put the keys of theData into theKeyList
   
   repeat for each line theKey in theKeyList
      put "fld" & theKey into theFieldName
      put "btn" & theKey into theButtonName
      put "mnu" & theKey into theMenuName
      put "rdo" & theKey into theRadioName
      put theKey into theDGName
      
      if there is a field theFieldName then
         put theData [theKey] into field theFieldName
         next repeat
      end if
      
      if there is a button theButtonName and the style of button theButtonName 
is "checkbox" then
         set the hilite of button theButtonName to theData [theKey]
         next repeat
      end if
      
      if there is a button theMenuName then
         put lineOffset(theData [theKey], the text of button theMenuName) into 
theFoundLine
         set the menuHistory of button theMenuName to theFoundLine
         next repeat
      end if
      
      if there is a group theRdoName then
         set the hilitedButtonName of group theRdoName to theData [theKey]
         next repeat
      end if
      
      if there is a group theDGName then
         try
            put arrayDecode(theData [theKey]) into theDGData
            set the dgData of group theDGName to theDGData
         catch theError
         end try
      end if
      
   end repeat
end populate


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to