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.

            <cfcomponent>
            <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>
            </cffunction>
            </cfcomponent>

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

            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#")>
                </cfoutput>

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

                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 :