One thing I'd like to point out about this article - all of the code is
missing var scope definitions. While this isn't as dangerous as missed
var statements in UDFs, it's still _very_ important in CFCs. 

For example:

<!--- Get user method --->
   <CFFUNCTION NAME="GetEMail" RETURNTYPE="string">
      <CFARGUMENT NAME="UserID"
                  TYPE="string"
                  REQUIRED="true"
                  HINT="Employee ID is required">

      <!--- Get user record --->
      <CFQUERY NAME="user" DATASOURCE="exampleapps">
      SELECT Email
      FROM tblEmployees
      WHERE EmployeeID='#ARGUMENTS.UserID#'
      </CFQUERY>

      <CFRETURN user.Email>
   </CFFUNCTION>

This should be: (I added ** to the new line, which should NOT be in real
code.)

<!--- Get user method --->
   <CFFUNCTION NAME="GetEMail" RETURNTYPE="string">
      <CFARGUMENT NAME="UserID"
                  TYPE="string"
                  REQUIRED="true"
                  HINT="Employee ID is required">

        <cfset var user = ""> **

      <!--- Get user record --->
      <CFQUERY NAME="user" DATASOURCE="exampleapps">
      SELECT Email
      FROM tblEmployees
      WHERE EmployeeID='#ARGUMENTS.UserID#'
      </CFQUERY>

      <CFRETURN user.Email>
   </CFFUNCTION>

You should also always use output=false in your CFC methods to cut down
on whitespace.

=======================================================================
Raymond Camden, ColdFusion Jedi Master for Hire

Email    : [EMAIL PROTECTED]
Yahoo IM : cfjedimaster

"My ally is the Force, and a powerful ally it is." - Yoda 

> -----Original Message-----
> From: Dick Applebaum [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, August 26, 2002 10:44 AM
> To: CF-Talk
> Subject: CFC Best methods?
> 
> 
> I Just read ben Forta's article on CFCs:
> 
> http://www.macromedia.com/desdev/mx/coldfusion/extreme/bforta_cfc.html
> 
> I have a couple of questions:
> 
> Ben shows 2 methods of using a CFC
> 
>     <cfinvoke....
> 
>     <cfobject...
> 
> Which is preferred, and why?
> 
> The docs show several methods of passing parameters to a cfc, 
> which is 
> preferred and why.
> 
> TIA
> 
> Dick
> 
> 
______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to