OO (two) eyes is definitely better than one, probably in most cases, the following seems to demonstrate that.  FYI, the test code is run under an app with session-enabled.


<h2>Find a structure's key/value pair</h2>
<p>
Note: an interesting thing about OO is that it is "spatial", for instance, the "internal" function may be placed below
its caller while the traditional structured programming can't.
</p>

<b>Source Code:</b><br>
<XMP>
&lt;cfset FORM.f1 = "field one string">
&lt;cfset FORM.f2 = "1">

&lt;cfoutput>
FORM:<BR> #aStructKeyValuePair(FORM)# <BR>
SESSION:<BR> #aStructKeyValuePair(SESSION)# <BR>
SERVER:<BR> #aStructKeyValuePair(SERVER)# <BR>
&lt;/cfoutput>

&lt;cffunction name="aStructKeyValuePair"
returntype="string"
access="private">

&lt;cfargument name="aS"
type="struct"
required="true">

&lt;cfloop item="a" collection="#arguments.aS#">
            &lt;cfoutput>
            #a# -- &lt;cfif IsSimpleValue(arguments.aS[a])>#arguments.aS[a]#&lt;cfelse>oops, complex data here&lt;/cfif><br>
            &lt;/cfoutput>
          &lt;/cfloop>

&lt;/cffunction>

</XMP>

<b>Output:</b><br><br>

<cfoutput>
FORM:<BR> #aStructKeyValuePair(FORM)# <BR>
SESSION:<BR> #aStructKeyValuePair(SESSION)# <BR>
SERVER:<BR> #aStructKeyValuePair(SERVER)# <BR>
</cfoutput>

<cffunction name="aStructKeyValuePair"
returntype="string"
access="private">

<cfargument name="aS"
type="struct"
required="true">

<cfloop item="a" collection="#arguments.aS#">
            <cfoutput>
            #a# -- <cfif IsSimpleValue(arguments.aS[a])>#arguments.aS[a]#<cfelse>oops, complex data here</cfif><br>
            </cfoutput>
          </cfloop>

</cffunction>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to