Hi Chris,

I would suggest the following:

mechlist.cfc
Even though you didn't entertain feedback on the CFC, I think you could increase code re-use by doing either having just 1 cffunction instead of 4. From what I could tell, the queries are the same with the exception of TRO.Weight. You can pass in an argument to determine the weight value of the list to be returned and using that in the query.


e.g.
<cffunction name="GetList" returntype="query" access="public">
        <cfargument name="XEra" default="2" required="no">
        <cfargument name="XFaction" default="1" required="yes">
        <cfargument name="XVType" default="1" required="no">
        <cfargument name="flag" default="1" required="no">
        <cfargument name="weight" required="yes" type="numeric">

        <cfquery name="qryList" datasource="touman">
                your SQL here
                ...
                WHERE   0 = 0 AND
                <cfif (flag is 1)>
                (((TRO.Faction)=#Arguments.XFaction#) AND
                ((TRO.VType)=#Arguments.XVType#) AND
                ((TRO.Weight)=#Arguments.weight#))</cfif>
        </cfquery>
</cffunction>

If you want to keep 4 different methods, I would suggest having a private method within the same CFC that does that actual querying and your public methods call the private method and pass in the necessary parameters, including the value for TRO.Weight.

e.g.
<cffunction name="AslList" access="public" returntype="query">
       <cfargument name="XEra" default="2" required="no">
       <cfargument name="XFaction" default="1" required="yes">
       <cfargument name="XVType" default="1" required="no">
       <cfargument name="flag" default="1" required="yes">

        <cfscript>
                arguments.weight = 4;
                qryList = GetList(argumentcollection=arguments);
        </cfscript>
        <cfreturn qryList>
</cffunction>

<cffunction name="HvyList" access="public" returntype="query">
       <cfargument name="XEra" default="2" required="no">
       <cfargument name="XFaction" default="1" required="yes">
       <cfargument name="XVType" default="1" required="no">
       <cfargument name="flag" default="1" required="yes">

        <cfscript>
                arguments.weight = 3;
                qryList = GetList(argumentcollection=arguments);
        </cfscript>
        <cfreturn qryList>
</cffunction>

<cffunction name="MedList" access="public" returntype="query">
       <cfargument name="XEra" default="2" required="no">
       <cfargument name="XFaction" default="1" required="yes">
       <cfargument name="XVType" default="1" required="no">
       <cfargument name="flag" default="1" required="yes">

        <cfscript>
                arguments.weight = 2;
                qryList = GetList(argumentcollection=arguments);
        </cfscript>
        <cfreturn qryList>
</cffunction>

<cffunction name="LtList" access="public" returntype="query">
       <cfargument name="XEra" default="2" required="no">
       <cfargument name="XFaction" default="1" required="yes">
       <cfargument name="XVType" default="1" required="no">
       <cfargument name="flag" default="1" required="yes">

        <cfscript>
                arguments.weight = 1;
                qryList = GetList(argumentcollection=arguments);
        </cfscript>
        <cfreturn qryList>
</cffunction>

<cffunction name="GetList" access="private" returntype="query">
        <cfargument name="XEra" default="2" required="no">
        <cfargument name="XFaction" default="1" required="yes">
        <cfargument name="XVType" default="1" required="no">
        <cfargument name="flag" default="1" required="yes">
        <cfargument name="weight" required="yes" type="numeric">

        <cfquery name="qryLists" datasource="touman">
                your SQL here
                ...
                WHERE   0 = 0 AND
                <cfif (flag is 1)>
                (((TRO.Faction)=#Arguments.XFaction#) AND
                ((TRO.VType)=#Arguments.XVType#) AND
                ((TRO.Weight)=#Arguments.weight#))</cfif>
        </cfquery>

        <cfreturn qryLists>
</cffunction>

In both cases, if you need to modify your SQL statement in the future for whatever reason, you only need to change the SQL in one place instead of four.

mechtest.cfm
You can replace all the cfinvoke tags with the following code:
<cfscript>
        objMechList = CreateObject("component","mechlist");
        MechQuery1 = objMechList.AslList(XFaction="#XFaction#");
        MechQuery2 = objMechList.HvyList(XFaction="#XFaction#");
        MechQuery3 = objMechList.MedList(XFaction="#XFaction#");
        MechQuery4 = objMechList.LtList(XFaction="#XFaction#");
</cfscript>

The rest of code can remain the same.

The main difference for using cfscript and CreateObject function over the cfinvoke tag is that the cfinvoke tag instantiates the CFC every time you use the tag. Because of the limitation of the tag to only one method per invocation, it's not very performance-friendly if you plan to use more than one method from the same CFC with the cfm page. Using the CreateObject function instantiates the CFC once and then you can call any public and remote functions by referencing the object variable ("objMechList" in the above example).

Hopefully I haven't droned on too long or didn't answer your question.

Rick Law



On Dec 16, 2004, at 7:58 AM, Chris Gomez wrote:

Here are the files I'm working with now.  the link to view final
result is: http://www.chaosmarch.com/test/mechtest.cfm

As I mentioned in a earlier post, I'm looking for a more streamlined
way to generate lists. The cfc method allows me to do this just fine
with the code in these two files.  What's throwing me for a loop is
how to use the cfscript to generate data to put into the cfoutput.

Chris


On Wed, 15 Dec 2004 17:33:44 -0600, Matt Woodward <[EMAIL PROTECTED]> wrote:
This really depends on what you're doing with your object.  If by
"tables" you mean something like you have a CFC with some data in it
and you want to output the data, then you would likely want to have a
"get" method in your CFC to get the data.  Let's say I have a CFC that
stores someone's name, and I have a getName() method to return the
name.

<cfoutput>This person's name is #myObject.getName()#.</cfoutput>

That clear it up any?  If not you'd probably have to post some code so
we can see better what exactly you're trying to accomplish.

Matt

On Wed, 15 Dec 2004 16:18:15 -0600, Chris Gomez <[EMAIL PROTECTED]> wrote:
unfortunately, not a whole lot. I mostly do basic cfm coding. this is
my first real attempt at OOP. if I put the <cfscript> in, then how do
I reference it when I create the <cfoutput> tables?

On Wed, 15 Dec 2004 15:38:41 -0600, Matt Woodward <[EMAIL PROTECTED]> wrote:
That would go in your CFM file. So let's say you have a CFC called
MyCFC.cfc. You would create and access it this way in your CFM file:


<cfscript>
// create an instance of MyCFC called myObject
myObject = CreateObject("component", "MyCFC");

// now that myObject is created, call some methods on it
myData = myObject.getSomeData();
myObject.doSomeStuff();
</cfscript>

That help?

Matt

On Wed, 15 Dec 2004 14:56:55 -0600, Chris Gomez <[EMAIL PROTECTED]> wrote:
I'm lost here. Do I put the cfscript into the .cfc or .cfm file? And,
how do I reference the myobj in the cfm file?


On Wed, 15 Dec 2004 13:25:58 -0600, Phillip Holmes
<[EMAIL PROTECTED]> wrote:

what do I do with the cfinvoke and cfinvokeargument?

Trash those nasty tags. I don't use them. The code I posted replace those
tags. Once you call your object, your methods therein will be available
without calling the object again.


Example:

<cfscript>

myobj = CreateObject('component','mycomponent');
// after your opbject in instantiated, you can call any function contained
in your object without calling the component again.
myobj.mymethod1();
myobj.mymethod2();
myobj.mymethod3();
myobj.mymethod4();


</cfscript>

Regards,

Phil

---
[This E-mail has been scanned for viruses.]

----------------------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe:
  http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
  http://www.dfwcfug.org/form_MemberRegistration.cfm


----------------------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe:
   http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
   http://www.dfwcfug.org/form_MemberRegistration.cfm




--
Matt Woodward
[EMAIL PROTECTED]
http://www.mattwoodward.com
----------------------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe:
  http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
  http://www.dfwcfug.org/form_MemberRegistration.cfm


----------------------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe:
   http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
   http://www.dfwcfug.org/form_MemberRegistration.cfm



-- Matt Woodward [EMAIL PROTECTED] http://www.mattwoodward.com ---------------------------------------------------------- To post, send email to [EMAIL PROTECTED] To unsubscribe: http://www.dfwcfug.org/form_MemberUnsubscribe.cfm To subscribe: http://www.dfwcfug.org/form_MemberRegistration.cfm


<mechlist.cfc><mechtest.cfm>


----------------------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe: http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe: http://www.dfwcfug.org/form_MemberRegistration.cfm





Reply via email to