4 Replies Latest reply on Dec 6, 2006 1:45 AM by cutie369

    looping over a structure

    cutie369 Level 1
      How do I loop over this structure to populate it with a Query Recordset?

      <cfset myStruct = objImage.getSize("images/products/largeImages/#Recordset1.elink#")>

      I really appreciate your help.
        • 1. Re: looping over a structure
          Charlie Griefer Level 1
          wouldn't you want to loop over the query data?

          i'm guessing you have a struct (myStruct) that holds the image height/width (myStruct.height and myStruct.width)? what is it that's coming from the query that you want the struct to hold (that it's not currently holding)?
          • 2. looping over a structure
            cutie369 Level 1
            I would like to populate the structure with the image file names that are coming from the query. The structure is built from a java object. Here is the function to create it.

            <cffunction name="getSize" returntype="struct" access="public" output="No">
            <cfargument name="Image" required="Yes" type="string">
            <cfset myImage = createObject("java", "javax.swing.ImageIcon")>
            <cfset myImage.init(expandpath(arguments.Image))>
            <cfset myStruct = StructNew()>
            <cfset myStruct.width = myImage.getIconWidth()>
            <cfset myStruct.height = myImage.getIconHeight()>
            <cfreturn myStruct>

            <cfobject component="imageSize" name="objImage">
            <cfset myStruct = objImage.getSize("/images/someimage.jpg")>
            width: #myStruct.width#
            height: #myStruct.height#

            Right now the structure only gives me the first row of the query. I have tried using the cfquery loop to populate the structure with now results. I suspect I am using the wrong syntac.
            • 3. Re: looping over a structure
              Charlie Griefer Level 1
              well, a structure by design can only have one key with a given name. you can't have myStruct.height multiple times for multiple images returned from the query.

              Sounds like you want an array of structs.
              • 4. Re: looping over a structure
                cutie369 Level 1
                I tried running your code but I get this error.

                <cfoutput query="Recordset1">
                <cfset ArrayAppend(myArray, objImage.getSize("images/products/largeImages/#Recordset1.elink#")>

                When I dump this it works.
                <cfset myStruct = objImage.getSize("images/products/largeImages/#Recordset1.elink#")>

                The error I am getting says.
                The CFML compiler was processing:

                an expression beginning with "ArrayAppend", on line 23, column 13.This message is usually caused by a problem in the expressions structure.
                a cfset tag beginning on line 23, column 7.

                The error occurred in C:\CFusionMX7\wwwroot\flash\setSize.cfm: line 23

                21 :
                22 : <cfoutput query="Recordset1">
                23 : <cfset ArrayAppend(myArray, objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
                24 : </cfoutput>
                25 :