> how can I ensure that my init function is called
Well, theres a lot of answers to that question, but heres two:


Way I would do it:

<cfscript>
 testcom = createobject("component","path.to.component");
 testcom.init();
</cfscript>


Another way, which I wouldnt do:

<cfcomponent>

<cfscript>
        init();
</cfscript>

<cffunction name="init" access="package" output="no">
        <cfset mystruct = structNew()>
        <cfset mystruct.initvar = "init varvalue">
</cffunction>

</cfcomponent>



-----Original Message-----
From: Ben Mueller [mailto:[EMAIL PROTECTED]
Sent: 27 May 2005 17:15
To: CF-Talk
Subject: RE: cfcomponent/function inheritence issue?


Kerry,

Thanks for your help.  You're certainly right about the duplicate
function...and of course I should have known that already.

But I'm a little confused about your statement that I shouldn't do this:

<cfif NOT isDefined("mystruct")><cfset this.init()></cfif>

I could call any function in my component at any time, so I have no way of
guaranteeing that init has been called previously.  If the above code is not
advised, then how can I ensure that my init function is called?


>If you do this:
>
><cfset var s = structNew()>
><cfset s = mystruct>
>
>Then s is not a struct, but a pointer to mystruct, so whenever you set a
>property of s, you are in fact setting a property of mystruct.
>
>
>Also, personally, theres no way i would do this:
>
><cfif NOT isDefined("mystruct")><cfset this.init()></cfif>
>
>
>I would do:
>
><cfset var s = duplicate(mystruct)>
>
>if mystruct isnt defined, then the component hasnt been inited, which means
>the code isnt right, and an error should be thrown.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:207878
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