Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: mike castillo
  Where is mike castillo?
 Joo Seng Road, Singapore
 Philippines
 mike castillo
 To: Matt Slay
  Where is Matt Slay?
 Birmingham
 Alabama - United States
 Matt Slay
 Tags
Subject: RE: Create collection of objects from cursor
Thread ID: 209443 Message ID: 209448 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Monday, December 29, 2008 2:20:07 AM         
   


> Do you know of a technique that will create a collection of objects where each object in the collection represents a row from a cursor?
>
> Basically, it would be like scattering a cursor to a collection of objects.
>
> Example:
>
> select * from ChildAlias;
> where fkey=ParentAlias.pkey;
> into cursor csrChildRecords
>
> Then, (pseudo code):
>
> scatter Cursor csrChildRecords to Collection collectionChildRecords
>
> or a method call like CreateCollectionFromCursor('CursorName', 'CollectionName')
>
> where the method would have a do/while loop that will create a collection, and then add an object to the collection for each row in the cursor.
>
> Have you seen thee need or application of such an approach?

Something like this?

*==========================================
	* Table records to Object                  
	* Sample: 	oTblObj = NULL                 
	*			= Scatter_TableObj("Temp",@oTblObj)
	*			?oTblObj(1).Fieldname          
	*==========================================
	PROCEDURE Scatter_TableObj(tcTable as String,oTblObj,tcFilter as String) && Scatter_TableObj("Temp",@oTblObj,"ID>0") ?oTblObj(1).Fieldname   
		LOCAL lnDime,lnCtr,cWhere
		
		cWhere = ""
		IF TYPE("tcFilter") = "C"
			cWhere = " Where " + tcFilter
		ENDIF 
		
		SELECT * FROM &tcTable &cWhere INTO CURSOR Tmp
		lnDime 	= _Tally
		lnCtr	= 0
		DIMENSION oTblObj[lnDime]
		LOCATE 
		SCAN 
			lnCtr = lnCtr + 1
			SCATTER NAME oTblObj[lnCtr] MEMO 
		ENDSCAN 
		USE IN SELECT("Tmp")
		RETURN oTblObj
	ENDPROC 


Kind regards,
Mike

ENTIRE THREAD

Create collection of objects from cursor Posted by Matt Slay @ 12/28/2008 10:27:57 PM
RE: Create collection of objects from cursor Posted by mike castillo @ 12/29/2008 2:20:07 AM
RE: Create collection of objects from cursor Posted by tushar @ 12/29/2008 7:21:01 AM
RE: Create collection of objects from cursor Posted by Boudewijn Lutgerink @ 12/29/2008 9:04:40 AM
RE: Create collection of objects from cursor Posted by Cetin Basoz @ 12/29/2008 1:16:51 PM