ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2012, 02:06 PM
BowlerDo0d BowlerDo0d is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 27 BowlerDo0d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 25 sec
Reputation Power: 0
Arrays of Component Objects

Before I give detailed examples, can anyone provide any insight into tips or tricks on creating arrays of objects? I'm currently attempting to create these arrays and it is giving me a bit of a problem.

I am attempting to create a main User structure that holds multiple variables including an array of account objects. Each account object has parameters as well as an array of sub-objects.

I am able to create the first array of objects, but when I refer to a function within one of those objects to create a sub-object, my code yells at me.

I can provide details later, but looking for any inside tips or tricks I may be forgetting first.

Thanks

Reply With Quote
  #2  
Old October 17th, 2012, 03:26 PM
BowlerDo0d BowlerDo0d is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 27 BowlerDo0d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 25 sec
Reputation Power: 0
After looking at this a little longer, I realize this may not make any sense without an example. Here is the code pages that I have:

User.cfc
Code:
<cfcomponent displayname="User" hint="Defines a user" output="false">

	<cffunction name="Init" output="false" access="public">
		<cfargument name="username" type="string" required="false" default="myuser" />
		
		<cfset variables.username = Trim(arguments.username) />
		<cfset variables.accounts = ArrayNew(1) />
		
		<cfreturn this />
	</cffunction>
	
	<cffunction name="addAccount" output="false" access="public" returntype="void">
		<cfargument name="accountNumber" type="numeric" required="true" />
		
		<cfset variables.accounts[ArrayLen(variables.accounts)+1] = createObject("component","/LearningArea/smahony/ObjectTesting/account").init() />
		
		<cfset variables.accounts[ArrayLen(variables.accounts)].addAddress(1234567890) />
		
		<cfreturn />
	</cffunction>
	
</cfcomponent>


Account.cfc
Code:
<cfcomponent displayname="Account" output="false">
	
	<cffunction name="init" access="public" returntype="void">
		<cfargument name="accountNumber" type="numeric" required="false" default="0" />
				
		<cfset variables.accountNumber = arguments.accountNumber />
		<cfset variables.addresses = arrayNew(1) />
		
		<cfreturn />
	</cffunction>
	
	<cffunction name="addAddress" output="false" access="public" returntype="void">
		<cfargument name="premiseID" type="numeric" required="true" />
		
		<cfset variables.addresses[ArrayLen(variables.addresses)] = createObject("component","address").init() />
		
		<cfreturn />
	</cffunction>
	
</cfcomponent>


Address.cfc
Code:
<cfcomponent displayname="Address" output="false">

	<cffunction name="Init" output="false" access="public">
		<cfargument name="addressID" type="numeric" required="false" default="0" />
		
		<!--- Initialize all variables needed --->
		<cfset variables.addressID = arguments.addressID />
		
		<cfreturn this />
	</cffunction>

</cfcomponent>


What is the best way to do this? When I try to add a new address object right after creating the account object it yells saying element 1 cannot be found. I'm at a loss (or not understanding what I'm trying to do)

Reply With Quote
  #3  
Old October 18th, 2012, 12:05 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,100 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 4 h 29 m 54 sec
Reputation Power: 966
You might be able to avoid this sort of problem if you just use ArrayAppend() to add items to the arrays.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Arrays of Component Objects

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap