Hi there,
Let me explain what I am trying to do,

the executive summary is that I want to count the number of arguments
passed into a function.
anyFunction(), might have 10 cfargument properties assigned to it.
But if I call;
anyFunction(arg1="1", arg2="2")

Then I somehow want to be able to retrieve the value 2 (2 passed in
variables).

Why,
Because I have a getObject method.
getObject is basically a cfquery and I filter the results of the
query, based on the arguments passed in.
so if I have;
getObject(myId = 1, yourId = 2);

then it creates SQL that looks like;
select STUFF
from myTable
where 1=1
and myid=1
and yourid=1
and...(add a number of arguments here....)

If I do NOT pass in any arguments, then the SQL retrieves ALL rows
from the table.
But I want to do is;
If no arguments are passed in  - create an empty object.

(we have a getAllObjects function to retrieve all rows)

maybe some code will help...

I have two snippets of code;
One is a function in a CFC, the other is some code in a CFM template
that calls the function - pretty simple.

myTestCFC.cfc:
<cffunction name="blah">
        <cfargument name="text" required="false" />
        <cfargument name="messageid" required="false" />
        <cfargument name="queryid" required="false" />
        <cfargument name="datasource" required="false" />

        <cfset var local = {} />
        <cfset local.length = #structCount(arguments)#>

        <cfreturn local.length>
</cffunction>


test.cfm:
<cfset myReturnVal = myTestCFC.blah(text="gav", queryid=3)>
<cfdump var="#myReturnVal#">
<br />
<cfif structKeyExists(messageCFC, "messageid")>
        Yes
<cfelse>
        No
</cfif>

the output of this code is;
4
No

The value 4 is because blah() has 4 arguments defined.
But structKeyExists, returns false...

How can it not exist but be accounted for?
surely one of the values is wrong?

If I change the code slightly to be;
<cfset local.length = #structKeyList(arguments)#>
instead of;
<cfset local.length = #structCount(arguments)#>

Then all four arguments defined in the "stub" of the function are
listed.

So is one of the values being returned a bug?

and lastly,
How do I go about "counting" actual passed in aerguments?
(I could write another function that loops through
structKeyLists(arguments),
then do a structKeyExists[i]
and increment a counter and do my own accounting....
but it just "seems" like there should be a nicer way to do it...

As always - Thanks for any thoughts!

Gavin.

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To post to this group, send email to cfaussie@googlegroups.com.
To unsubscribe from this group, send email to 
cfaussie+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en.

Reply via email to