The string = #SomeStr#

Now call it with this code:

zObj is #IIf (IsDefined ("zObj"), DE (""), DE ("NOT"))# defined.

We see that the init function does run but the object is not available for use! That is, it wasn't "created" in the usual sense. Can anybody confirm that the object is created on their server or that this used to work? Given the name and stated purpose of CreateObject() this seems like a bug regardless. This is on CF 7.00, standard edition if that makes a difference. Thanks, -- MikeR [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => MikerRoo [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Kronin555 [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> CreateObject is not "creating" my CFC! - Coldfusion - Advanced Techniques

CreateObject is not "creating" my CFC! - Coldfusion - Advanced Techniques

Instantializing a CFC with an initializer no longer works for us. (I could have swore it did at one time). Consider this CFC: <!--- File: CFC_WithInit.cfc ---> <CFCOMPONENT> <CFFUNCTION name="Init" returntype="void"> <CFARGUMENT name="SomeStr"> <CFOUTPUT> <h1>The string = #SomeStr#</h1> </CFOUTPUT> </CFFUNCTION> </CFCOMPONENT> <!--- End of File. ---> Now call it with this code: <CFSET zObj = CreateObject ("component", "CFC_WithInit").Init ("Sic semper tyranus!")> <CFOUTPUT> <h1>zObj is #IIf (IsDefined ("zObj"), DE (""), DE ("NOT"))# defined.</h1> </CFOUTPUT> We see that the init function does run but the object is not available for use! That is, it wasn't "created" in the usual sense. Can anybody ...

  1. #1

    Default CreateObject is not "creating" my CFC!

    Instantializing a CFC with an initializer no longer works for us. (I could
    have swore it did at one time).

    Consider this CFC:
    <!--- File: CFC_WithInit.cfc --->
    <CFCOMPONENT>

    <CFFUNCTION name="Init" returntype="void">

    <CFARGUMENT name="SomeStr">

    <CFOUTPUT> <h1>The string = #SomeStr#</h1> </CFOUTPUT>
    </CFFUNCTION>
    </CFCOMPONENT>
    <!--- End of File. --->


    Now call it with this code:
    <CFSET zObj = CreateObject ("component", "CFC_WithInit").Init ("Sic semper
    tyranus!")>

    <CFOUTPUT> <h1>zObj is #IIf (IsDefined ("zObj"), DE (""), DE ("NOT"))#
    defined.</h1> </CFOUTPUT>


    We see that the init function does run but the object is not available for
    use! That is, it wasn't "created" in the usual sense.

    Can anybody confirm that the object is created on their server or that this
    used to work?

    Given the name and stated purpose of CreateObject() this seems like a bug
    regardless.

    This is on CF 7.00, standard edition if that makes a difference.

    Thanks,
    -- MikeR

    MikerRoo Guest

  2. #2

    Default Re: CreateObject is not "creating" my CFC!

    MikerRoo wrote: 

    normally (as if i know what i'm talking about when it comes to OO) you'd
    return the object, ie in the init methd add <cfreturn this> otherwise
    skip the init() bits when you create the CFC & just run init() later as
    if it were a simple method (which it is as you've written it).
    PaulH Guest

  3. #3

    Default Re: CreateObject does not "create" a CFC when aninitializing function is used.

    Your init function is returning void.

    The result of this statement:
    <CFSET zObj = CreateObject ("component", "CFC_WithInit").Init ("Sic semper
    tyranus!")>
    is to create the object, call Init on it, and set zObj to what's returned from
    Init (which is nothing, in your case),

    The return type on an init function should be the component type. In your
    example, it should be CFC_WithInit

    Check the CF7 Developer's guide on writing CFCs, specifically initializing
    instance data.

    http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/
    wwhelp.htm?context=ColdFusion_Doentation&file=p art_dev.htm

    Cut and pasted from there:
    ==========================
    A useful technique is to define a method named init(), which initializes an
    instance of a CFC, acting as a constructor. The init() method can initialize
    constants and return an instance of the component to the calling page. The
    following code illustrates an example of an init() method:

    <cfcomponent displayname="shoppingCart">
    <cffunction name="init" access="public" output="no"
    returntype="shoppingCart">
    <cfargument name="shoppingCartID" type="UUID" required="yes">
    <cfset variables.shoppingCartID = arguments.shoppingCartID>
    <cfreturn this>
    </cffunction>

    <!--- Additional methods go here. --->
    </cfcomponent>


    Kronin555 Guest

  4. #4

    Default Re: CreateObject does not "create" a CFC when aninitializing function is used.

    :o
    Thanks, Kronin555.

    You've proved that I should go home and get some sleep.

    Of course, you're right.

    Thanks,
    -- MikeR
    MikerRoo Guest

  5. #5

    Default Re: CreateObject is not "creating" my CFC!

    Your response came in as I was replying to Kronin555 (Despite your timestamp
    being earlier here, the notice emails show Kronin555 first.)

    Anyway, you're both right and I feel extra stupid (for working tired and then
    posting a "problem").

    Thanks,
    -- MikeR

    MikerRoo Guest

  6. #6

    Default Re: CreateObject is not "creating" my CFC!

    MikerRoo wrote: 

    the newgroups gateway to the forums lags (i've been having some
    heebie-jeebie problems w/the webforums lately so i swapped to the
    newsgroups--though i much prefer the webforums).

    well since you heard the same answer (more or less) from two different
    people, it's gotta be right ;-)
    PaulH Guest

Similar Threads

  1. Server.CreateObject("Access.Application")
    By David Di Donato in forum ASP Components
    Replies: 1
    Last Post: November 8th, 08:56 AM
  2. "Server.CreateObject failed" intermittently
    By Dennis in forum ASP Components
    Replies: 1
    Last Post: December 26th, 01:41 PM
  3. Replies: 5
    Last Post: July 28th, 06:26 AM
  4. server.createobject("wscript.shell")
    By Ray at in forum ASP
    Replies: 0
    Last Post: July 11th, 08:51 PM
  5. Server.CreateObject("ADODB.Stream")
    By Andrew Durstewitz in forum ASP
    Replies: 1
    Last Post: July 3rd, 06:34 PM

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
  •