I added: <CFRETURN FrmTypes> and run the app. again,
still get the same
error.
In your example you don't want to return the function, you
want to
return the query you generated in the function.
<cfreturn getTypes>
That will remove the error you are receiving but the function
will not
be doing what you want. The way it is written it will still
run the
query every time the function is called to get the data. To
do what you
stated, not have the query created many times, you are going
to want to
have one function (or in the component pseudo constructor)
create the
query and store it, then another function to read it back to
any code
that needs to use it. You will then need to store the
initiated
component in some type of persistent variable so that the
query is
persisted and does not get re-run unnecessarily.
<CFCOMPONENT>
<CFFUNCTION Name="set_FrmTypes" ReturnType="void">
<cfset var getTypes = ""> <!--- The var keyword
initilizes the
getTyes variable to be local to this function to prevent
problems. --->
<cfquery name="getTypes" datasource="MyDB">
Select * from TblForms order by FormID Asc
</cfquery>
<cfset variables.types = getTypes> <!--- This sets
the query to an
internal variable of the component/object--->
</CFFUNCTION>
<cffunction name="get_frmTypes" returnType="query">
<cfreturn variables.types> <!--- This returns the
query from the
internal variable--->
</cffunction>
</CFCOMPONENT>
Then in your calling code.
<!--- This invokes the component calling the set_frmTypes
function to
initilize the query and stores the result in the application
scope so it
can be used anywhere in the given application --->
<CFINVOKE Component="getFrmTypes" Method="set_FrmTypes"
ReturnVariable="application.FormTypesQuery">
<!--- The calls the above saved component and gets the
query out of it. --->
<CFINVOKE Component="#application.FromTypesQuery#"
Method="get_frmTypes"
ReturnVariable="theQuery">