-Matt
On Feb 10, 2004, at 6:12 PM, Raymond Camden wrote:
I'm late to this thread, but what is wrong with this:
<cffunction ....> <cfset var tempStruct = ""> <cfset var data = arrayNew(1)> <cfset var x = 1>
<cfloop index="x" from=1 to=10> <cfset tempStruct = structNew()> <cfset tempStruct.foo = "moo"> <cfset arrayAppend(data,duplicate(tempStruct))> </cfloop>
Won't this handle it just fine?
======================================================================= ====
Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc (www.mindseye.com)
Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia)
Email : [EMAIL PROTECTED] Blog : www.camdenfamily.com/morpheus/blog Yahoo IM : morpheus
"My ally is the Force, and a powerful ally it is." - Yoda
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Matt Liotta Sent: Tuesday, February 10, 2004 5:09 PM To: [EMAIL PROTECTED] Subject: Re: [CFCDev] How should I define variable in a CFC?
Interesting! I have also found that variables created in loops are a big problem. For example, suppose you want to create an array of structures. You write a loop that creates a structure, assigns some keys, and then appends the structure to the array. How do you declare the structure as local to that function? Well you can't without resorting to some drastic measures.
-Matt
On Feb 10, 2004, at 6:00 PM, Nathan Dintenfass wrote:
worry aboutFrom the informal testing I have done, you don't need toquery is run.that.CFQUERY will overwrite the cfquery variable every time acfquery"In fact, from what I've seen, doing what you suggest with "varyou stilldoesn't even work to keep the "cfquery" variable local to the method. For instance:
<cfcomponent> <cffunction name="getEmployees"> <cfset var get = ""> <cfset var cfquery = ""> <cfquery name="get" datasource="cfsnippets"> select * from employees </cfquery> <cfreturn get> </cffunction> <cffunction name="getLastExecutionTime"> <cfreturn cfquery.executionTime> </cffunction> </cfcomponent>
If you call getEmployees() and then getLastExecutionTime()get the time of the query. To make things even stranger,if you addthis line of code inside getEmployees after the query:still confuses
<cfset writeOutput(cfquery.executionTime)>
it won't work unless you get rid of the var statement with cfquery.
Funky.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jay Gibb Sent: Tuesday, February 10, 2004 2:39 PM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
Hey Barney,
In your example below wouldn't you also need..
<cfset var cfquery = "">
So that the cfquery structure returned by the <cfquery> tag didn't get dumped into the shared variables scope?
- j.
P.S. Pardon my re-iterating over this question, but itto set themme.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Barney Boisvert Sent: Tuesday, February 10, 2004 11:04 AM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
Yeah, you have to define everything first. And you haveto use theall to a value as well. You can reasign later, though, and the variable name is still protected. This comes in very handy with queries:
<cffunction name="getlist"> <cfset var get = "" /> <cfquery name="get" datasource="#variables.my.dsn#"> SELECT * FROM myTable ORDER BY name </cfquery> <cfreturn get /> </cffunction>
You should do that for ALL queries, even if you don't needThomas (PPC)name afterwards (for insert, update and/or delete queries).
Cheers, barneyb
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Schreck,happens asSent: Tuesday, February 10, 2004 10:57 AM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
That makes sense, but it seems somewhat limiting. Whatto set theyou process through the logic of your method and you needat the top,value of a variable? By declaring the variable with vargiven youris it still protected further in your code? I assume somust know allanswer (I think I answered my own question). So, youimmediatelyvariables you want protected prior to getting into your method logic, correct?
Tom
-----Original Message----- From: Nathan Dintenfass [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 12:45 PM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
As the error says, you can only use var at the beginning of a method ;)
In other words, you can only declare your local variablescan declareafter CFARGUMENT and before any other code. Though, in 6.1 you[mailto:[EMAIL PROTECTED]them at the top of the first CFSCRIPT block inside the function body (a nice improvement, as you had to use CFSET for all var declarations in 6.0).
-----Original Message----- From: [EMAIL PROTECTED]a variableBehalf Of Schreck, Thomas (PPC) Sent: Tuesday, February 10, 2004 10:37 AM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
I've run into situations trying to use 'var' in front ofcan only benameand it produces an error. Something to the affect "vararound using var?usedat the beginning of a method". What are the rulesconditions, becausefunctions/methods. It
Thanks - Tom Schreck
-----Original Message----- From: Barney Boisvert [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 12:02 PM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] How should I define variable in a CFC?
Using the 'var' keyword is only allowed insidecreates a local variable that only exists for that specificinvocationof the function. Such variables are immune to racefunctions), into CFCs, youthey are bound to a specific invocation. This is not specificcan use it in any function definition (including CFSCRIPTis around.oroutside a CFC.accessible only
Using the 'variables' scope creates a private variableto your CFC. It exists as long as the instance of the CFCthey are sharedSuchvariables are NOT immune to race conditions, becausewww.mail-archive.com/[EMAIL PROTECTED]on a singleacross the instance, and multiple clients may be calling methodsinstance at the same time.except that
Using the 'this' scope is just like the 'variables' scope,client code, asthe variables are public, so the can be read or written bywww.mail-archive.com/[EMAIL PROTECTED]well as methods of the CFC.
Cheers, barneyb
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Troy Simpson Sent: Tuesday, February 10, 2004 9:38 AM To: [EMAIL PROTECTED] Subject: [CFCDev] How should I define variable in a CFC?
All,
I have been away from coldfusion for about a year or so and now need to get back into in. I am using ColdFusion MX for this project that I am working on. I need some clarification if possible.
How should I define variables in a CFC and why? What is the difference between the three?
<cfcomponent> <cfset var dsn = "DataSourceName"> <cfset variables.dsn = "DataSourceName"> <cfset this.dsn = "DataSourceName"> </cfcomponent>
Thanks, Troy
-- Troy Simpson Applications Analyst/Programmer, OCPDBA, MCSE, SCSA North Carolina State University Libraries Campus Box 7111 | Raleigh | North Carolina ph.919.515.3855 | fax.919.513.3330 E-mail: [EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
