Name

StructGet

Synopsis

                  
                  
                  StructGet("path")

Returns a structure (flat or nested) from the specified path. Allows you to create nested structures without the need for multiple StructNew( ) calls. StructGet( ) takes a single argument, path, that specifies the path to the nested structure (including XML document objects) you want to return. StructGet( ) returns a pointer to the substructure specified as the last element in path. The StructGet( ) function automatically creates all the necessary structures and substructures specified in path if they do not exist. The StructGet( ) function can also be used to create nested one-dimensional arrays. The following example demonstrates the use of this function for creating a nested structure:

<!--- Create the Grades.Mary structure --->
<cfset temp1 = StructGet("Grades.Mary")>
<cfset temp1.Test1 = 98>                 
<cfset temp1.Test2 = 92>
<cfset temp1.Test3 = 100>
<cfset temp1.Test4 = 90>
   
<!--- Create the Grades.Tom structure --->
<cfset temp2 = StructGet("Grades.Tom")>
<cfset temp2.Test1 = 96>                 
<cfset temp2.Test2 = 88>
<cfset temp2.Test3 = 94>
<cfset temp2.Test4 = 90>
   
<cfdump var="#Grades#">

You can also use StructGet( ) to return the structures from an XML document object as this example demonstrates:

<cfset MyEmployees = QueryNew("Name,Title")> <cfset QueryAddRow(MyEmployees, 3)> <cfset QuerySetCell(MyEmployees, "Name", "Pere Money", 1)> <cfset QuerySetCell(MyEmployees, "Title", "President", 1)> <cfset QuerySetCell(MyEmployees, "Name", "Aaron Ridge", 2)> ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.