Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does a Form's Data Environment supercede SET DATABASE TO?

Status
Not open for further replies.

toddsevans

Technical User
Aug 20, 2004
19
US
I am working on a function which will allow my users to deploy their data to an alternate directory. The problem I am having is that once I move the data I am unable to get my program to use the deployed data. Everything I have tried makes it look as though I have set the database properly but changes to data effect the tables in my program directory instead of the deployed data directory.

So I am wondering if because I used the data environment on my forms to handle opening and closing tables if I have also hard coded a path to the program directory. Should I be explicitly opening the tables with the full path in code instead of using the DE?

Here is my code to set the current database:
Code:
USE DOC IN 0
SELECT doc
STORE ALLTRIM(doc.data_dir) TO pc_data_dir
CLOSE TABLES ALL
CLOSE DATABASES ALL
OPEN DATABASE (pc_data_dir + "iloan.dbc")
SET DATABASE TO (pc_data_dir + "iloan.dbc")
WAIT WINDOW DBC()
The Wait Window tells me that the current DBC is in the deployed data directory.

Anybody have a suggestion how to proceed?

Thanks,

Todd Evans
 
Hi Todd,

unfortunately the datenvironment (=DE) stores the full DBF Path with the tables you use, so there has to be some code in "BeforeOpenTables" to correct this programmtically for all Cursor objects of the DE if you want to use another DBC. The DE links to those tables you pulled in there at design time.

I'd recommend not to use DE and if you really want to, only use the Methods and open tables and set relations with code, instead of using the visual part of the DE.

This problem you have is the most important reason to not use the DE, another one is: If you later want to change forms to classes, these don't have a DE and it's harder to make the transition from SCX to classes of a VCX, if you'd like to change your application to OOP style.

Bye, Olaf.
 
Todd,

The easiest way to deal with this is to set the data environment's AutoOpenTables and AutoCloseTables to .F. (these are properties of the DE itself, not of the cursors within it). Then, in the form's Load event, explicitly open the tables. You don't need to open the database, although it does no harm if you do.

Olaf,

the datenvironment (=DE) stores the full DBF Path with the tables you use .... I'd recommend not to use DE

I have to disagree. If the path stored in the DE is not present at run time, VFP will simply look in the search path for the data, which is usually what you want.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks Mike. I am curious though. If I explicitly open the tables in the load event what is the advantage of using the data environment in the first place?
 
Hi, Olaf!
unfortunately the datenvironment (=DE) stores the full DBF Path with the tables you use, so there has to be some code in "BeforeOpenTables" to correct this programmtically for all Cursor objects of the DE if you want to use another DBC. The DE links to those tables you pulled in there at design time.
I think this is some kind of mystifying DE.
The from table stores a relative path and Form designer convert it to full path.
DE of the form (I don't mean here s DE class) allows me work with databases located in different folders by switching databases on the fly.


Juri Shutenko
Municipality of Maardu, Estonia
 
Todd,

If I explicitly open the tables in the load event what is the advantage of using the data environment in the first place?

The main advantage is that it lets you drag and drop onto the form design surface. That's an important advantage, because it also sets the ControlSource and several other properties.

That said, you can get exactly the same benefits by dragging from the project manager. If you don't plan to drag from the DE, and if you explicitly open tables in the Load, then you might as well not bother with the DE.

Mike

Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top