You've all inspired me. Here's your all purpose "checkCaller" function. It
can check for the calling template as either the first calling template, or
as any calling template. It also works with CFM and CFC callers!
<CFFUNCTION NAME="checkCaller" ACCESS="public" RETURNTYPE="boolean"
OUTPUT="false">
<CFARGUMENT NAME="sRequiredTemplate" TYPE="string" REQUIRED="true"
HINT="The CFC or CFM that is required to call this object.">
<CFARGUMENT NAME="bIsDirectCaller" TYPE="boolean" REQUIRED="false"
DEFAULT="true" HINT="If set to true, the required template must be the
directly preceding caller.">
<CFSET var arTagContext = "">
<!--- Capture the call TagContext //--->
<CFTRY>
<CFTHROW TYPE="checkCaller" MESSAGE="TestMessage">
<CFCATCH TYPE="any">
<CFSET arTagContext = cfcatch.TagContext>
</CFCATCH>
</CFTRY>
<!--- If we're requiring the tempalte to be the direct caller, then
check the first template call element in TagContext //--->
<CFIF arguments.bIsDirectCaller>
<CFLOOP FROM="1" TO="#ArrayLen(arTagContext)#" INDEX="i">
<CFIF arTagContext[i].id IS "CF_TEMPLATEPROXY">
<CFIF Find(sRequiredTemplate,
arTagContext[i].template)>
<CFRETURN true>
<CFELSE>
<CFRETURN false>
</CFIF>
</CFIF>
</CFLOOP>
<CFRETURN false>
<CFELSE>
<!--- If we're the tempalte can be any caller, then check
loop through TagContext until we find it //--->
<CFLOOP FROM="1" TO="#ArrayLen(arTagContext)#" INDEX="i">
<CFIF arTagContext[i].id IS "CF_TEMPLATEPROXY" AND
Find(sRequiredTemplate, arTagContext[i].template)>
<CFRETURN true>
</CFIF>
</CFLOOP>
<CFRETURN false>
</CFIF>
</CFFUNCTION>
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Danilo Celic
Sent: Friday, January 16, 2004 10:36 AM
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] Making sure is not called out of sequence
Bryan F. Hogan wrote:
> The stacktrace has an array of callers. I would modify his code to check
> the arrayIndex().
Ok, good to know thanks, Bryan.
Can anyone point me to a good reference on cfcatch.StackTrace as this
livedocs page:
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-a10.htm#wp339503
8
doesn't mention the cfcatch.StackTrace that is in this bit of code that was
posted:
<CFCATCH TYPE="any">
<CFSET sStack = cfcatch.StackTrace>
</CFCATCH>
--
Enjoy,
Danilo Celic
| Extending Knowledge, Daily
| http://www.CommunityMX.com/
Those who aren't looking often have their eyes open widest.
----------------------------------------------------------
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]