Re: cfscript functions in CFCs

2005-03-03 Thread Jared Rypka-Hauer - CMG, LLC
On Thu, 3 Mar 2005 13:30:29 -0500, Adam Haskell <[EMAIL PROTECTED]> wrote:
> If I have option values I do this
> function bob(required)
> {
> var optional = '';
> if (arraylen(arguments) EQ 2)
>optional = arguments[2];
> ...
> }
> 
> I think you will find this common practice if you look trhough a good
> chunk of the UDFs on cflib.org.
> 
> Adam H
> 

Ahh, excellent...

THANK YOU. I hadn't gotten around to messing with it further. I was
planning to send 3 args to a function with one arg defined, then use
"return arguments;" and a CFDUMP to see exactly what I got back.

>From that perspective, you could create a var'ed structure, loop the
arguments structure and write all the argument variables to the local
structure, and then use structKeyExists for detecting their presence
for conditional processing:


function myFunction() {
var myContainer = structNew();

for (i in arguments) {
myContainer[i] = arguments[i];
}

if (structKeyExists(myContainer,"argumentName")) {
{code here}
}
else {
{other code here}
}
}


Laterz,
J

-- 
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com

~|
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:197387
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


Re: cfscript functions in CFCs

2005-03-03 Thread Adam Haskell
If I have option values I do this 
function bob(required)
{
var optional = '';   
if (arraylen(arguments) EQ 2)
   optional = arguments[2];
...
} 

I think you will find this common practice if you look trhough a good
chunk of the UDFs on cflib.org.

Adam H

On Wed, 2 Mar 2005 23:20:25 -0600, Jared Rypka-Hauer - CMG, LLC
<[EMAIL PROTECTED]> wrote:
> This also works:
> 
> test.cfc
> -
> 
>
>function getCGI(cV) {
>try {
>return cgi[cV];
>}
>catch (any cfScriptError) {
>return cgi;
>}
>}
>
> 
> 
> temp.cfm
> 
> 
> 
> 
> The first one outputs "w2ksrv1" which is the server name of my dev box.
> 
> The second one does a cfdump of the CGI struct.
> 
> I was messing around with using various if statements to detect cV,
> and the try/catch worked immediately. structKeyExists always
> recognized that cV existed, even when it wasn't passed in. len(cV)
> threw an error because it tried to access a variable that hadn't been
> set. I haven't worked with function definitions in cfscript enough to
> be sure exactly the best way to declare a default value for one...
> but that snippet ran just fine.
> 
> Laterz,
> J
> 
> On Wed, 2 Mar 2005 14:56:18 -0700, Paul <[EMAIL PROTECTED]> wrote:
> > This must be easier than I'm making it this afternoon.
> >
> > All the UDFs from cflib.org are written in cfscript.  Is there a way to
> > store them in a CFC, say Util.cfc, and then call them from another CFC?
> > When I attempt to do so CF can't find the function.  I experimented and
> > wrapped the cfscript inside a cffunction definition and now CF apparently
> > can't see the arguments I'm passing in.
> >
> > So, how does one call cfscript-based functions from within a CFC?
> >
> > -paul
> >
> > http://www.houseoffusion.com/banners/view.cfm?bannerid=48
> > Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
> >
> 
> --
> Continuum Media Group LLC
> Burnsville, MN 55337
> http://www.web-relevant.com
> http://cfobjective.neo.servequake.com
> 
> 

~|
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:197303
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


RE: cfscript functions in CFCs

2005-03-03 Thread Paul
> This was a fun, if simple, excercise... thanks Paul!

For as often as I'm confused, it's nice that at least my questions at least
occasionally lead to something positive for someone out there!  Thanks for
looking into it, as well.



~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

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


Re: cfscript functions in CFCs

2005-03-03 Thread Jared Rypka-Hauer - CMG, LLC
Hey Paul...

Here's the latest test. :) Note that in test.cfc, I've got both
CFINVOKE and createObject() styles of accessing the second CFC... they
both work just fine. I used one, then remarked it out and used the
other too and figured I'd leave them both in as examples.

temp.cfm
-



test.cfc
-










test2.cfc
-


function getCGI(cV) {
var cVlocal = '';

if (len(cV)) {
cVlocal = cgi[cV];
} else {
cVlocal = cgi;
}

return cVlocal;
}




I think it's worth noting that since test.cfc is calling
test2.getCGI(arguments["cgVar"]) and cgVar is being created in the
cfarguments of test.getCGIVar() with a default value of "", I was able
to dispense with the try/catch and use an if... sort of speaks to
Facade patterns, doesn't it? My need to always supply an empty
argument is hidden by my public API.

Kinda neat.

This was a fun, if simple, excercise... thanks Paul!

Laterz,
J

On Thu, 3 Mar 2005 08:19:29 -0700, Paul <[EMAIL PROTECTED]> wrote:
> Thanks for playing around with this, Jared.
> 
> In your experiments did you try calling test.getCGI() from within a second
> cfc as well?  (temp.cfm creates test1.cfc; test1.cfc calls test.getCGI() as
> part of its processing.)
> 
> If that works for you my difficulty may be a difference between BD and CFMX;
> my life would be simpler if I could talk my way into a second MX license...
> 
> 


-- 
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com

~|
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:197257
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


RE: cfscript functions in CFCs

2005-03-03 Thread Paul
> Well this syntax is invalid -- if your psuedocode is accurate... You
> can't declare a function within a function. Or that was what I thought

You're right - my function-within-a-function code block caused an error on
CFMX server.  It does seem like a pretty silly idea after having it pointed
out...  Curiously, no error was thrown (related to the nested function) on
the BlueDragon box we use for a few internal apps.  

And it turns out my real problem was a stinking typo - one that I missed
time and time again even while specifically looking for typos.  I'll just
slink off into my corner...

(Thanks for your time, though.)



~|
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:197243
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


RE: cfscript functions in CFCs

2005-03-03 Thread Paul
Thanks for playing around with this, Jared.

In your experiments did you try calling test.getCGI() from within a second
cfc as well?  (temp.cfm creates test1.cfc; test1.cfc calls test.getCGI() as
part of its processing.)  

If that works for you my difficulty may be a difference between BD and CFMX;
my life would be simpler if I could talk my way into a second MX license...

-Original Message-
From: Jared Rypka-Hauer - CMG, LLC [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 10:20 PM
To: CF-Talk
Subject: Re: cfscript functions in CFCs

This also works:

test.cfc
-


function getCGI(cV) {
try {
return cgi[cV];
} 
catch (any cfScriptError) {
return cgi;
}
}



temp.cfm




The first one outputs "w2ksrv1" which is the server name of my dev box.

The second one does a cfdump of the CGI struct.

I was messing around with using various if statements to detect cV,
and the try/catch worked immediately. structKeyExists always
recognized that cV existed, even when it wasn't passed in. len(cV)
threw an error because it tried to access a variable that hadn't been
set. I haven't worked with function definitions in cfscript enough to
be sure exactly the best way to declare a default value for one... 
but that snippet ran just fine.

Laterz,
J


~|
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:197242
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


Re: cfscript functions in CFCs

2005-03-03 Thread Ben Doom
> 
> 
>   function myFunc...
>   return resultVar
> 
> 
> That method nets "function myFunc not found".

It's been a while since I've played with CFC's, but from what I 
remember, that should work.  Are you calling object.myfunc()?

> That method gets me a "variable myArg is undefined" message, curiously
> enough referencing the cfreturn line of code.  It seems the argument passes
> muster when it enters the function but can't be called in the return call?

IIRC, cfscripts always error at the last line of the function, or the 
first line of the script if it's not a function.  But I could be 
completely off my rocker, because that just doesn't sound right.

--Ben


~|
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:197240
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


Re: cfscript functions in CFCs

2005-03-02 Thread Jared Rypka-Hauer - CMG, LLC
Hehe, apparently I'm replying to this message in stages... I've been
playing with this.

So... according to the cf documentation,  all args specified in the
function declaration are mandatory. It seems that the only way to use
optional arguments in cfscript function arguments is to use a try
block like I did. I finally settled for this:

test.cfc
--


function getCGI(cV) {
try {
var cVlocal = cgi[cV];
}
catch (any localErrorVar) {
var cVlocal = cgi;
} 
return cVlocal;
}



Same code as before in the calling page, though, and the cfdumps both work fine.

Laterz,
J

On Wed, 2 Mar 2005 14:56:18 -0700, Paul <[EMAIL PROTECTED]> wrote:
> This must be easier than I'm making it this afternoon.
> 
> All the UDFs from cflib.org are written in cfscript.  Is there a way to
> store them in a CFC, say Util.cfc, and then call them from another CFC?
> When I attempt to do so CF can't find the function.  I experimented and
> wrapped the cfscript inside a cffunction definition and now CF apparently
> can't see the arguments I'm passing in.
> 
> So, how does one call cfscript-based functions from within a CFC?
> 
> -paul
> 
> 
> http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=15114.13525.4
> Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
> 


-- 
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com

~|
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:197227
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: cfscript functions in CFCs

2005-03-02 Thread Jared Rypka-Hauer - CMG, LLC
This also works:

test.cfc
-


function getCGI(cV) {
try {
return cgi[cV];
} 
catch (any cfScriptError) {
return cgi;
}
}



temp.cfm




The first one outputs "w2ksrv1" which is the server name of my dev box.

The second one does a cfdump of the CGI struct.

I was messing around with using various if statements to detect cV,
and the try/catch worked immediately. structKeyExists always
recognized that cV existed, even when it wasn't passed in. len(cV)
threw an error because it tried to access a variable that hadn't been
set. I haven't worked with function definitions in cfscript enough to
be sure exactly the best way to declare a default value for one... 
but that snippet ran just fine.

Laterz,
J

On Wed, 2 Mar 2005 14:56:18 -0700, Paul <[EMAIL PROTECTED]> wrote:
> This must be easier than I'm making it this afternoon.
> 
> All the UDFs from cflib.org are written in cfscript.  Is there a way to
> store them in a CFC, say Util.cfc, and then call them from another CFC?
> When I attempt to do so CF can't find the function.  I experimented and
> wrapped the cfscript inside a cffunction definition and now CF apparently
> can't see the arguments I'm passing in.
> 
> So, how does one call cfscript-based functions from within a CFC?
> 
> -paul
> 
> http://www.houseoffusion.com/banners/view.cfm?bannerid=48
> Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
> 


-- 
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com

~|
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:197226
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


Re: cfscript functions in CFCs

2005-03-02 Thread Jared Rypka-Hauer - CMG, LLC
This works:

test.cfc
---


function getCGI() {
return cgi;
}



temp.cfm
--



So, while it had never dawned on me to try it, that's kinda cool...

It never occurred to me that you could write functions inside a CFC
using cfscript function declarations. The things you learn from this
internet thingie...

Anyway, that much works... don't know how your CFC is laid out, so I
can't speak to your specific issue.

Laterz,
J

On Wed, 2 Mar 2005 14:56:18 -0700, Paul <[EMAIL PROTECTED]> wrote:
> This must be easier than I'm making it this afternoon.
> 
> All the UDFs from cflib.org are written in cfscript.  Is there a way to
> store them in a CFC, say Util.cfc, and then call them from another CFC?
> When I attempt to do so CF can't find the function.  I experimented and
> wrapped the cfscript inside a cffunction definition and now CF apparently
> can't see the arguments I'm passing in.
> 
> So, how does one call cfscript-based functions from within a CFC?
> 
> -paul

> Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
> 


-- 
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com

~|
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:197223
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


RE: cfscript functions in CFCs

2005-03-02 Thread S . Isaac Dealey
> 
> 
> 
>   
>   function myFunc2...
>   return resultVar
>   
> 
> 

> That method gets me a "variable myArg is undefined"
> message, curiously
> enough referencing the cfreturn line of code.  It seems
> the argument passes
> muster when it enters the function but can't be called in
> the return call?

Well this syntax is invalid -- if your psuedocode is accurate... You
can't declare a function within a function. Or that was what I thought
-- ECMAScript allows this, but not CFScript that I'm aware. It's
possible that the CFML parser could be not noticing the fact that
there's a function declared inside a function and so the content of
the inner function is never being executed... although in that case I
would expect it to return the argument unmodified... You're also
returning twice, although that would just mean the  tag
isn't used / redundant.

But in any event, it might be easier for us to help out if you provide
an actual section of the CFC with the whole function code in it as
you're trying to use it.

s. isaac dealey 954.522.6080
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://macromedia.breezecentral.com/p49777853/
http://www.sys-con.com/story/?storyid=44477&DE=1
http://www.sys-con.com/story/?storyid=45569&DE=1
http://www.fusiontap.com


~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

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


RE: cfscript functions in CFCs

2005-03-02 Thread Paul
> You'd have to either convert the argument list from the function to
>  tags or you can inject the created function into the cfc
> like this:

What I'm trying is similar to what you suggest:  



function myFunc...
return resultVar


That method nets "function myFunc not found".





function myFunc2...
return resultVar




That method gets me a "variable myArg is undefined" message, curiously
enough referencing the cfreturn line of code.  It seems the argument passes
muster when it enters the function but can't be called in the return call?



~|
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:197205
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: cfscript functions in CFCs

2005-03-02 Thread S . Isaac Dealey
> This must be easier than I'm making it this afternoon.



> All the UDFs from cflib.org are written in cfscript.  Is
> there a way to
> store them in a CFC, say Util.cfc, and then call them from
> another CFC?
> When I attempt to do so CF can't find the function.  I
> experimented and
> wrapped the cfscript inside a cffunction definition and
> now CF apparently
> can't see the arguments I'm passing in.



> So, how does one call cfscript-based functions from within
> a CFC?

You'd have to either convert the argument list from the function to
 tags or you can inject the created function into the cfc
like this:



function blah(...) { ... }

variables.blah = blah;



At least I think that might work. I know you can inject functions into
CFC's -- I've done it. I've not tried it in this particular context.

s. isaac dealey   954.927.5117
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework
http://www.fusiontap.com




~|
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:197200
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