Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seperate DBC for each project number?
Message
From
08/08/1999 17:09:38
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00251276
Message ID:
00251294
Views:
9
>In putting together an app, I ask the user for a project number upon startup. If the project does not exist, I'd like to replicate the DBC and it's tables in a sub-directory and use that as the data for my main application.
>
>I'm wanting to do this for easy backup, organization and archiving - and to make it easier for users to manage their files.
>
>That being said, I'm having trouble figuring out how to create the data environment of my primary application. How do I tell my form to look in a certain directory for it's DBC, instead of the one I used for design? Do I need to empty the data environment and instead open the tables and create the relationships in the calling program? I know this is the way I always used to do it - perhaps I'm just getting lazy!
>
>TIA

You just need to change the database property for the objects in the dataenvironment of each form. This has to be done before the tables are opened, so do it a ,method called from form.load or Form.DataEnvironment.BeforeOpenTables. Here is the code from my ChangeDataPath method in my base form class. It is called with the path as a parameter, usually from form.load. The form gets its datapath from the application object.
LPARA tcNewDataPath

LOCAL lnCnt, loObj, lcDBC, lcNewDataPath

IF TYPE("tcNewDataPath") <> "C"
	RETURN .F.
ELSE
	lcNewDataPath = tcNewDataPath
ENDIF

LOCAL ARRAY laList[1]

*** Get Object Members of DE
=AMEMBERS(laList, THISFORM.DATAENVIRONMENT, 2)
IF EMPTY(laList[1])
	*** Nothing in DE
	RETURN
ENDIF

IF ALEN( laList,1 ) > 0
	FOR i = 1 TO ALEN(laList,1 )
		loObj =  EVAL("ThisForm.DataEnvironment."+laList[i])
		IF LOWER(loObj.BASECLASS ) = 'cursor' AND "\"$loObj.DATABASE
			IF !EMPTY(loObj.DATABASE)
				*** Contained Table
				lcDBC = SUBSTR(loObj.DATABASE, RAT('\', loObj.DATABASE))
				loObj.DATABASE = tcNewDataPath + lcDBC
				IF !DBUSED(loObj.Database)
					OPEN DATABASE (loObj.Database)
				ENDIF
				SET DATABASE TO (loObj.Database)
			ELSE
				*** Free Table
				lcDBC = SUBSTR( loObj.CursorSouce, RAT('\',loObj.CursorSouce))
				loObj.CursorSouce = tcNewDataPath + lcDBC
			ENDIF
		ENDIF
	NEXT
ENDIF
Erik Moore
Clientelligence
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform