Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cycle though tables in DataEnviornment
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00314653
Message ID:
00314828
Views:
33
>Nick,
>
> I'm not sure, that I understand, how can we take it of from the loop. It evaluates loObj depending on laCursorList[i]...
>

Like this: :)

*- loop thru cursors and replace database name with correct database to use -*
IF ALEN( laCursorList,1) > 0
FOR I = 1 TO ALEN(laCursorList,1)
loObj = EVAL("Thisform.DataEnvironment." + laCursorlist[i])
IF UPPER(loObj.BASECLASS) = 'CURSOR' AND '\' $ loObj.Database
IF NOT EMPTY(loObj.Database)
*- table in database -*
loObj.Database = oApp.gcDbPath + oApp.gcDbName
ELSE
*- free table -*
loObj.CursorSource = oApp.gcDbPath + oApp.gcDbName
ENDIF
ENDIF
NEXT
	IF NOT DBUSED(loObj.Database)
		OPEN DATABASE (loObj.Database)
	ENDIF
	SET DATABASE TO (loObj.Database)

ENDIF

When we go out of the loop, loObj still contains the last processed object in the Dataenvironment. However, this may not work properly if the last object in DE is a Relation which has no .Database property.
My concern is only to OPEN/SET DATABASE once, and it can be done different ways, for example through adding a local variable llSetDatabase which will take care of this inside existing code:
*- loop thru cursors and replace database name with correct database to use -*
IF ALEN( laCursorList,1) > 0
	LOCAL llSetDatabase
	llSetDatabase = .t.
	FOR I = 1 TO ALEN(laCursorList,1)
		loObj = EVAL("Thisform.DataEnvironment." + laCursorList[i])
		IF UPPER(loObj.BASECLASS) = 'CURSOR' AND '\' $ loObj.Database
			IF NOT EMPTY(loObj.Database)
				*- table in database -*
				loObj.Database =  oApp.gcDbPath + oApp.gcDbName
				IF llSetDatabase = .t.
					IF NOT DBUSED(loObj.Database)
						OPEN DATABASE (loObj.Database)
					ENDIF
					SET DATABASE TO (loObj.Database)
					llSetDatabase = .f.
				ENDIF
			ELSE
				*- free table -*
				loObj.CursorSource = oApp.gcDbPath + oApp.gcDbName
			ENDIF
		ENDIF
	NEXT
ENDIF


Nick
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform