Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Call a function within the same CFC component

Community Beginner ,
Aug 17, 2007 Aug 17, 2007
Hi,
/* Niewbie Question */
I've got a strange problem. When I try to call a function from another in the same CFC component, I get an Error named : « Entity has incorrect type for being called as a function.»
I've looked on many forums and searched in Google Groups. I haven't still found a workaround for that problem.
I thought I've paid attention not o use two times the same name...
Can anyone tell me what error I made ?

My sample code to reproduce this error is included

The complete error message is :
Entity has incorrect type for being called as a function.
The symbol you provided superfunction is not the name of a function.

The error occurred in C:\ColdFusion8\wwwroot\admin\_components\test.cfc: line 6

4 : <cfinvoke
5 : method = "superfunction"
6 : returnVariable = "myReturn">
7 : </cfinvoke>
8 : <cfset some_text = myReturn>
6.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Aug 17, 2007 Aug 17, 2007
OK, solved it with all your tips !!!

Thanks a lot to everybody

Here is the final code for the others...
Translate
LEGEND ,
Aug 17, 2007 Aug 17, 2007
In your superfunction, scope your argument variables.

In your coolfunction, pass two arguments to the superfunction.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2007 Aug 17, 2007
Thanks for replying fast,

I forgot to pass the variables in the exemple, I attached corrected code.
I know what you mean by scoping variables, but how do I do it in CF ? (just three days since my begenning in CF...)
Can you re-paste my code once corrected with the right scoping so I can see how to do this, please? I think it will then make a good exemple post for other niewbies who encounter this problem...

Thanks !
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 17, 2007 Aug 17, 2007
quote:

<!--- Instanciate component --->
<cfinvoke method="objTest.coolfunction">



The error is caused by including the variable name in the "method" value. The correct syntax here is
<cfobject component="test" name="objTest">
<cfinvoke component="#objTest#" method="coolfunction">

As mentioned
1. When referencing variables, include the scope. For example, use "arguments.myArg1" instead of just "myArg1".
2. If a variable is only used inside the function, use the keyword "VAR" to place it in the local scope.
3. Though some are optional, its good to use the attributes like "type", "returnType", "required" and "access"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 17, 2007 Aug 17, 2007
try the following:

<cfcomponent>

<cffunction name="coolfunction" access="public" returnType="any" output="true">

<cfset some_text= Superfunction(myArg1,myArg2)/>
</cffunction>

<cffunction name="superfunction" access="private" returnType="any" output="true">
<cfargument name="myArg1">
<cfargument name="myArg2">
<cfset myVariable = myArg1&" toto "&myArg2>
<cfreturn myVariable>
</cffunction>

</cfcomponent>

also, I will suggest that you remove the under-score from the folder name "_components"

Good Luck
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2007 Aug 17, 2007
Replys to qateef :

Thanks for replying fast too.
I tried your thing but it returns me the following error :
ariable SUPERFUNCTION is undefined.

The error occurred in C:\ColdFusion8\wwwroot\admin\_components\test.cfc: line 6

4 :
5 : <cffunction name="coolfunction" access="public" returnType="any" output="true">
6 : <cfset some_text = superfunction("tata","titi")>
7 : <cfreturn some_text>
8 : </cffunction>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 17, 2007 Aug 17, 2007
change the access for the superFunction to Public instead of Private. Make sure the spelling is correct and you need to include the type for each <cfargument
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 17, 2007 Aug 17, 2007
having Access set to private is totally correct - no need to change it to public - you're not calling superfunction() directly so having it set to private is spot on.

Let's have a fresh look at the code you've got so far and we'll get this nailed...

john.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2007 Aug 17, 2007
> <cfinvoke method="objTest.coolfunction">

Should this not be:

<cfinvoke component="#objTest#" method="coolfunction">

?

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 17, 2007 Aug 17, 2007
> Should this not be:
> <cfinvoke component="#objTest#" method="coolfunction">

Nevermind. "Beat me to the punch"
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2007 Aug 17, 2007
LATEST
OK, solved it with all your tips !!!

Thanks a lot to everybody

Here is the final code for the others...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources