Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loop through Object Properties
Message
 
 
To
13/10/2008 10:58:35
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01354594
Message ID:
01354599
Views:
13
This message has been marked as the solution to the initial question of the thread.
>I want to loop through an object and evaluate each value.
* obj2cursor

LPARAMETERS toObject, tcCursor, tcOpt
LOCAL lcCursor, lcOpt, lvPropVal, lcPropName, lnI, laStru[1], lnRows, lcPropType

lcCursor = IIF( Empty( tcCursor) Or VarType(tcCursor) <> "C", SYS(2015), tcCursor)
lcOpt = UPPER(IIF( Empty( tcOpt) Or VarType(tcOpt) <> "C", "", tcOpt))

lcCmd = "CREATE CURSOR " + lcCursor 

lnCount = AMEMBERS(laProps, toObject, 0)
DIMENSION laStru(lnCount, 16)
laStru = ""

lnRows = 0

FOR lnI=1 TO lnCount
	lcPropName = LOWER(laProps[lnI])
	lvPropVal = EVALUATE( "toObject." + lcPropName) 
	lcPropType = TYPE("toObject." + lcPropName)
	
	lnDp = 0
	DO CASE
	CASE lcPropType = "C"
		lnSize = LEN(lvPropVal)
		IF lnSize = 0
			lnSize = 1
		ENDIF 
		IF lnSize > 254
			lcPropType = "M"
			lnSize = 0
		ENDIF	
	CASE lcPropType = "L"
		lnSize = 0
	CASE lcPropType = "D"
		lnSize = 0
	CASE lcPropType = "T"
		lnSize = 0
	CASE lcPropType = "N"
		lcVal = ALLTRIM(PADL(lvPropVal,20))
		lnSize = LEN(lcVal)
		IF "." $ lcVal
			lnDp = lnSize - RAT(".", lcVal)
		ELSE	
			lcPropType = "I" 
			lnSize = 0
		ENDIF
	OTHERWISE 
		* Unsupported data types 
		LOOP
	ENDCASE		

	lnRows = lnRows + 1
	
	laStru[lnRows, 1] = lcPropName
	laStru[lnRows, 2] = lcPropType
	laStru[lnRows, 3] = lnSize
	laStru[lnRows, 4] = lnDp
	laStru[lnRows, 5] = .T.
	laStru[lnRows, 6] = .F.

	
ENDFOR

IF lnRows > 0
	DIMENSION laStru(lnRows, 16)
	* Make a cursor with fields defined by laStru
	CREATE CURSOR (lcCursor) FROM ARRAY laStru
	INSERT INTO (lcCursor) FROM NAME toObject
	llOk = .T.
ELSE
	llOk = .F.
ENDIF	

RETURN llOk
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform