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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using The Data Environment

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have an application which in its main program opens a database MyData. While I am developing the application the database will perhaps be in my development folder, C:\Dev\Data. At run time it will be in whatever folder the user chooses to use, so perhaps E:\CompanyX\Datafiles. My application handles this fine.

At present, however I tend to open a particular table, say Customers, with an instruction like this in the Init() method :
USE Customers INDEX Customers ALIAS Cus IN 0
. . . and at the end I close the table with
SELECT Cus
USE
There are probably better ways, but this is the way that I know !

I feel that I should be using the Data Environment. To that end, during development, I can View the Data Environment, and can open the relevant file, c:\Dev\Data\Customers.dbf. This seems to work OK, and when I run the form I see that fields which I have dragged onto the form do indeed display the relevant values.

However, when I examine the .scx file (by browsing it as a table), I see that the record defining the cursor has its properties field containing :
Alias = “Customers”
CursorSource= “..\..\data\customers.dbf”​

Am I doing this right? When the application is installed on the customers site it will presumably try to find a data folder, and this will fail. How can I get round this?

A few further questions.
1. When I am developing the form and go the Data Environment and do Right-Click Add, I thought this might have offered the option of opening a table or a database container. However VFP only appears to offer the option of putting a single table into the environment. I don’t really mind in this case, because I am only concerned with one table, but I wonder whether there is the more general option of including a database within the data environment for a form.

2. When I exit from the form, is the table automatically closed? And if so, where is the code that does that.

3. Although I have a database open within my application, when I open a table, I always refer to it by its .dbf filename. Presumably VFP works out that the table is part of a database and opens that database if necessary. Is there a way of referring to the table by its own name within the database, if that name is different to the name of the .dbf file within the folder?

Sorry for the rather basic questions.

Andrew
 
Mike, I've used that sort of code when working with apps that use multiple sets of same-structured data.

At my last job all of our end users managed data for multiple customers, and each customer had it's own set of data in its own subdirectory. (It was horizontal partitioning to avoid the 2GB limit.) Any user could switch companies at will many times in a day. I actually preferred forcing where VFP looked for its data.
 
I agree with Dan in his case. You could also remove one customer related path and add another customer related path, but you never know what lurks in caches. Anyway, additionally closeing all tables, databases and datasessions the PATH solution should work, too. Setting paths of the DE objects anyway forces the right location as the first thing VFP tries and that of course works fastest.

Not using the datasession at all I would make the customer folder a prefix for any USE and solve the problem even more directly.

Bye, Olaf.
 
>Not using the datasession at all
Sorry, of course I meant to say "Not using the data environment at all..."

Bye, Olaf.
 
I've had problems in the past when I was using the database environment in forms with private data sessions, since your open database in your main session doesn't carry over. I use similar code in the BeforeOpenTables method as that listed above except that I also include a call to the routine that I use to setup my standard VFP session environment (like set safety, set talk, set deleted, etc). Too long ago though - I can't think what the problem was [sad]

Rob Spencer
Caliptor Pty Ltd
 
I've had problems in the past when I was using the database environment in forms with private data sessions, since your open database in your main session doesn't carry over.

Well, that's the whole point of a private data session. It has its own opinions about what databases and tables are open. I don't see it as a problem. I generally just open the tables that I need for the form or class in question. (I don't use the BeforeOpenTables method, although I accept that there might sometimes be reasons to do so.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top