Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create cursor from object
Message
De
06/01/2012 11:13:16
 
 
À
02/01/2012 00:41:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Divers
Thread ID:
01532019
Message ID:
01532318
Vues:
48
>Let's say I have created a simple object from Empty, and that I have added sevaral properties (and values) to it. The properties could be Integers, floats, dates, strings, logicals, etc.
>
>Now I want to create a cursor with fields named the same as the properties, and have 1 row in the cursor where the row has the values from the object properties.
>
>Basically, I want a function like this:
>
>CreateCursorFromObject(oMyObject, cCursor)
loObj = CREATEOBJECT("Empty")
ADDPROPERTY(m.loObj, "id", 1)
ADDPROPERTY(m.loObj, "name", "test")
ADDPROPERTY(m.loObj, "bdate", DATE(1980, 1, 1))

IF CreateCursorFromObject(m.loObj, 'test')
	SELECT test
	BROWSE
ENDIF

*!* A very simple cursor from object function
*!* not contain field width / error handler
FUNCTION CreateCursorFromObject(toObject, tcCursor)
	LOCAL ARRAY laFields[1]
	LOCAL i, lcFields, lcField, lvValue, lcType, lcTemp, lnPos, lnLen, lnDec
	lcFields = ""
	FOR i = 1 TO AMEMBERS(laFields, m.toObject)
		lcField = m.laFields[m.i]
		lvValue = EVALUATE("m.toObject." + m.lcField)
		lcType = VARTYPE(m.lvValue)
		lcFields = m.lcFields + "," + m.lcField + " " + m.lcType
		DO CASE
		CASE m.lcType == "C"
			lcFields = m.lcFields + "(" + LTRIM(STR(LEN(m.lvValue))) + ")"
		CASE m.lcType $ "NY"
			lcTemp = TRANSFORM(m.lvValue)
			lnLen = LEN(m.lcTemp)
			lnPos = AT(".", m.lcTemp)
			IF m.lnPos > 0
				lnDec = m.lnLen - m.lnPos - 1
				lnLen = m.lnLen - m.lnDec - 1
				lcFields = m.lcFields + "(" + LTRIM(STR(m.lnLen)) + "," + LTRIM(STR(m.lnDec)) + ")"
			ELSE
				lcFields = m.lcFields + "(" + LTRIM(STR(m.lnLen)) + ")"
			ENDIF
		CASE m.lcType $ "DT"
		ENDCASE
	ENDFOR
	IF !EMPTY(m.lcFields)
		m.lcFields = TRIM(SUBSTR(m.lcFields, 2))
		CREATE CURSOR (m.tcCursor) ( &lcFields. )
		APPEND BLANK
		GATHER NAME m.toObject
	ENDIF
	RETURN USED(m.tcCursor)
ENDFUNC
Regards,
Ony
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform