The way you are using init() it is unnecessary.  You can do this in the 
components pseudo constructor.  

<cfcomponent>

<cfset mystruct = structNew()>
<cfset mystruct.initvar = "init varvalue">
<cfreturn this>

<cffunction name="func1" access="public" output="no">
        <cfset var s = structNew()>
....

Anything that is placed between the opening <cfcomponent> and the first 
<cffunction> will always be run.  The main problem with this is there is no way 
to pass arguments to the "constructor".  If one needs the constructor then, the 
init() function is the way to go.



--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
 
"C code. C code run. Run code run. Please!"
- Cynthia Dunning

....-----Original Message-----
....From: Ben Mueller [mailto:[EMAIL PROTECTED]
....Sent: Friday, May 27, 2005 8:27 AM
....To: CF-Talk
....Subject: cfcomponent/function inheritence issue?
....
....I've just started learning cfcomponents as of a few days ago, and have
....liked what I've seen so far, but I'm having what I think is an
....inheritence issue.
....
....I have a component with three functions:  an init, and then two other
....functions.  The init function sets a bunch of variables that I'd like to
....have access to throughout the component.  The other functions invoke the
....init function if the init variables haven't been set yet.
....
....In each function, I'd like to return the global vars returned by the init
....function, plus a bunch of stuff unique to each function.  The trouble is
....that the variables from the first function call end up as part of the
....overall instance data, and are then somehow getting returned in
....subsequent function calls.
....
....I'm sure it's something silly, but here's my sample code:
....
....
....<cfcomponent>
....
....<cffunction name="init" access="package" output="no">
....    <cfset mystruct = structNew()>
....    <cfset mystruct.initvar = "init varvalue">
....    <cfreturn this>
....</cffunction>
....
....<cffunction name="func1" access="public" output="no">
....    <cfset var s = structNew()>
....    <cfif NOT isDefined("mystruct")><cfset this.init()></cfif>
....    <cfset s = mystruct>
....    <cfset s.func1var = "value1">
....    <cfreturn s>
....</cffunction>
....
....<cffunction name="func2" access="public" output="no">
....    <cfset var t = structNew()>
....    <cfif NOT isDefined("mystruct")><cfset this.init()></cfif>
....    <cfset t = mystruct>
....    <cfset t.func2var = "value2">
....    <cfreturn t>
....</cffunction>
....
....</cfcomponent>
....
....
.........and here's how I'm invoking it:
....
....<cfobject name="testcom" component="path.to.component">
....
....<cfset func1output = testcom.func1()>
....<cfset func2output = testcom.func2()>
....
....<cfdump var=#func1output#>
....<cfdump var=#func2output#>
....
....What I would expect from the first cfdump is a structure containing the
...."initvar" and "func1var"; and from the second cfdump a structure with
...."initvar" and "func2var".  However, my second cfdump call returns
...."initvar", "func1var" and "func2var".
....
....So, it would seem that the line of code where I declare this in my first
....function:
....
....<cfset s = mystruct>
....
....is not only setting s to the value of mystruct, but also the other way
....around.  That is a surprise to me.
....
....Any help is appreciated.
....
....Thanks in advance,
....Ben Mueller
....
....
....
....
....
....
....

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:207879
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to