Professional Web Applications Themes

CFObject vs CFInvoke - Coldfusion - Advanced Techniques

Hi All, this is just a question to get a better understanding of the use of CFObject vs CFInvoke. I was just reading and the understanding that I get was if you are going to call a method serveral times within the same page it is better to use cfobject. If if you are going to make a single call to a method you use cfinvoke. Is there any harm in using cfobject for everything?? Any help or advice would be appreciated. Thanks in advance Maurice...

Sponsored Links
  1. #1

    Default CFObject vs CFInvoke

    Hi All, this is just a question to get a better understanding of the use of
    CFObject vs CFInvoke. I was just reading and the understanding that I get was
    if you are going to call a method serveral times within the same page it is
    better to use cfobject. If if you are going to make a single call to a method
    you use cfinvoke. Is there any harm in using cfobject for everything??

    Any help or advice would be appreciated.

    Thanks in advance

    Maurice

    Sponsored Links
    EdmondsM Guest

  2. #2

    Default Re: CFObject vs CFInvoke

    It's one extra line of code.


    Originally posted by: EdmondsM
    Hi All, this is just a question to get a better understanding of the use of
    CFObject vs CFInvoke. I was just reading and the understanding that I get was
    if you are going to call a method serveral times within the same page it is
    better to use cfobject. If if you are going to make a single call to a method
    you use cfinvoke. Is there any harm in using cfobject for everything??

    Any help or advice would be appreciated.

    Thanks in advance

    Maurice



    Dan Guest

  3. #3

    Default Re: CFObject vs CFInvoke

    Hi Dan, I am not sure I am understanding when you say " It's one extra line of code. " Can you explain what you are saying.
    EdmondsM Guest

  4. #4

    Default Re: CFObject vs CFInvoke

    Re: one extra line of code.

    Instead of just doing:
    <cfinvoke ...>

    you have to do:
    <cfobject ...>
    <cfinvoke ...>
    Kronin555 Guest

  5. #5

    Default Re: CFObject vs CFInvoke

    EdmondsM wrote: 

    There's no harm in it--the common wisdom used to be that because
    cfinvoke creates the object, calls the method, then destroys the object,
    if you're going to do that several times you're better off using
    cfobject or createobject(). I've been told (but haven't verified) that
    the compiler is a bit more intelligent now so you can use cfinvoke
    multiple times and behind the scenes it will handle the single object
    instantiation for you. Don't quote me on that because frankly unless an
    engineer tells me for sure that's the case (or I do some Java
    decompiling and research on my own), I don't buy it. :-)

    All that being said, I very, very rarely wind up using cfinvoke, simply
    because in many cases I'm doing multiple calls to the same object, or
    because I tend to have an init() method that needs to be called first in
    order to make my objects useful (e.g. for an object that deals with a
    datasource I have to pass the datasource name in and that gets used by
    many of the functions within the object), cfinvoke doesn't do me much good.

    Hope that helps,
    Matt

    --
    Matt Woodward
    com
    Team Macromedia - ColdFusion
    mpwoodward Guest

  6. #6

    Default Re: CFObject vs CFInvoke

    Hi Kronin555, so you have to use both of them??
    EdmondsM Guest

  7. #7

    Default Re: CFObject vs CFInvoke

    Not quite
    <cfobject ...>
    plus
    <cfset x=objectname.functionname()>

    Originally posted by: Kronin555
    Re: one extra line of code.

    Instead of just doing:
    <cfinvoke ...>

    you have to do:
    <cfobject ...>
    <cfinvoke ...>



    Dan Guest

  8. #8

    Default Re: CFObject vs CFInvoke

    Not quite
    <cfobject ...>
    plus
    <cfset x=objectname.functionname()>

    That's one way. An equivalent way using the 2 lines I listed is:

    <cfobject component="MyComponent" name="componentInstance">
    <cfinvoke component="#componentInstance#" method="functionname"
    returnVariable="x" />


    Kronin555 Guest

  9. #9

    Default Re: CFObject vs CFInvoke

    Hi Matt, So when you use cfobject do you also have to include a cfinvoke??
    EdmondsM Guest

  10. #10

    Default Re: CFObject vs CFInvoke

    cfobject instantiates an object. It does not run any methods. You need
    another command to run a method. That command could be cfinvoke, or cfset, or
    something inside a cfscript tag.

    Originally posted by: EdmondsM
    Hi Matt, So when you use cfobject do you also have to include a cfinvoke??



    Dan Guest

  11. #11

    Default Re: CFObject vs CFInvoke

    Hi Dan, So if I am understanding correclty.....you use cfobject to call the component but you use cfset or cfinvoke to call the methods?? I am on the right track??
    EdmondsM Guest

  12. #12

    Default Re: CFObject vs CFInvoke

    Here's an example with a web service - same concept as using a component.

    With CFINVOKE, you create the object and call a method with the same tag.
    With CFOBJECT, you create an object, then you use CFSET to call method(s).

    Personally I always stick to CFOBJECT (well, the CreateObject function, but
    same thing) since it's rare that I want to call only one function, and I find
    it easier.

    <cfinvoke
    webservice="[url]/currency.cfc?wsdl"
    method="IsValidCurrency"
    returnVariable="Result"
    Currency="GBP"
    />

    <cfinvoke
    webservice="[url]/currency.cfc?wsdl"
    method="IsValidCurrency"
    returnVariable="Result"
    Currency="USD"
    />

    -------------

    <cfobject
    webservice="[url]/currency.cfc?wsdl"
    name="MyWebService"
    />

    <cfset Result = MyWebService.IsValidCurrency(Currency='GBP')/>

    <cfset Result = MyWebService.IsValidCurrency(Currency='USD')/>

    boughtonp Guest

  13. #13

    Default Re: CFObject vs CFInvoke

    Hi Peter, when you call the component with cfobject, it is presistent so you can use cfset to call the different methods right??
    EdmondsM Guest

  14. #14

    Default Re: CFObject vs CFInvoke

    Yup, it persists as long as the scope it is placed in does.

    So you can use <cfobject component="MyComponent"
    name="Application.MyComponent"/> and not have to use CFOBJECT again unless you
    clear the application scope.

    boughtonp Guest

  15. #15

    Default Re: CFObject vs CFInvoke

    Correct-a-mundo.

    Originally posted by: EdmondsM
    Hi Dan, So if I am understanding correclty.....you use cfobject to call the
    component but you use cfset or cfinvoke to call the methods?? I am on the
    right track??



    Dan Guest

  16. #16

    Default Re: CFObject vs CFInvoke

    It all goes like this??

    <cfobject component="MyComponent" name="MyName">

    <cfset method1 = "MyName.CalltheMethodYouWant">
    <cfset method2 = "Myname.CallTheMethodYouWant">

    Am I correct??
    EdmondsM Guest

  17. #17

    Default Re: CFObject vs CFInvoke

    EdmondsM wrote: 

    This has already been answered I think, but just to add further
    clarification, no you don't *have* to use cfinvoke. Once the object is
    created you can just call methods on the instance using
    objectName.methodName notation. For example let's assume there's a
    Person CFC that has methods for getting and setting the person's name.
    One way to use this object would be like this:

    <cfset myPerson = CreateObject("component", "Person") />
    <cfset myPerson.setName("matt") />
    <cfoutput>#myPerson.getName()#</cfoutput>

    I very, very rarely use cfinvoke.

    Hope that helps,
    Matt

    --
    Matt Woodward
    com
    Team Macromedia - ColdFusion
    mpwoodward Guest

  18. #18

    Default Re: CFObject vs CFInvoke

    Almost... no quotes but you use a pair of parenthesis even without arguments:
    <cfset method1 = MyName.CalltheMethodYouWant()>
    boughtonp Guest

Similar Threads

  1. cfobject
    By djfletch in forum Coldfusion Server Administration
    Replies: 0
    Last Post: February 28th, 04:19 PM
  2. CFOBJECT reload
    By WalterAlb in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: November 15th, 09:42 PM
  3. CFOBJECT error
    By loopthis! in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 14th, 04:27 PM
  4. CFObject with ASP Script
    By Radioactive45 in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 27th, 04:01 PM
  5. Using CfObject
    By Tom CF in forum Macromedia ColdFusion
    Replies: 5
    Last Post: April 7th, 05:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139