Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing DBCs within an application
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00540872
Message ID:
00541823
Views:
38
This message has been marked as the solution to the initial question of the thread.
Hi Rodney.

>I'm trying to figure out how to change what dbc my application points to programmatically. The DBC tables and such are the same, I just need to be able to point to one versus the other for debugging purposes.

One change you'll need to make is the Database property of cursor objects in the DataEnvironment of forms and reports. Here's how I do it.

I set the AutoOpenTables property of the DataEnvironment to .F. so it doesn't do its thing until I tell it to. I have this code in the Load method of the form:
with This
  if not .DataEnvironment.AutoOpenTables
    SetDataDirectory(.DataEnvironment)
    .DataEnvironment.OpenTables()
  endif
endwith
This calls a routine named SetDataDirectory to set the proper location of my DBC and then tells the DataEnvironment to open the tables.

Here's the code for SetDataDirectory. It assumes there's an application object named oApp with a property called cDataDir that contains the current data directory. So, simply changing oApp.cDataDir will result in forms opening the correct set of tables the next time they're run. Change the logic as necessary to match where you store the directory.
lparameters toDE
local laObjects[1], ;
  lnObjects, ;
  lcDirectory, ;
  lcCommon, ;
  lnI, ;
  loObject, ;
  lcDatabase, ;
  lcTable
lnObjects   = amembers(laObjects, toDE, 2)
lcDirectory = oApp.cDataDir
for lnI = 1 to lnObjects
  loObject = evaluate('toDE.' + laObjects[lnI])
  if upper(loObject.BaseClass) = 'CURSOR'
    lcDatabase = loObject.Database
    if empty(lcDatabase)
      lcTable = loObject.CursorSource
      loObject.CursorSource = lcDirectory + ;
        substr(lcTable, rat('\', lcTable) + 1)
    else
      loObject.Database = lcDirectory + ;
        substr(lcDatabase, rat('\', lcDatabase) + 1)
    endif empty(lcDatabase)
  endif upper(loObject.BaseClass) = 'CURSOR'
next lnI
Doug
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform