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

DataEnvironment 2

Status
Not open for further replies.

kimsue

Programmer
Mar 5, 2002
52
US
I am developing my first application in Visual Foxpro. For each form in the application, I am using the same code in the BeforeOpenTables method of the DataEnvironment. The code sets the path for the data location (using variables saved in a mem file). I saved a form as a class and selected this class as the basis for all new forms, however; the class does not save the DataEnvironment. Where would I put the code in this method(BeforeOpenTables) so that ALL forms are pointing to the correct data location? It doesn't seem likely that I should be changing this method in every form...??? Thanks in advance for your help.
 
The DE cannot be subclasses.
Can setting the path SET PATH TO C:\datapath in your main program (before you call any forms) work?
 
Kimsue,
I may not be able to help you here, but I certainly sympathize... I have a number of BEFOREOPENTABLES calls that I make, and I have to put them in every time on every form. It's better than the "Old days", but this is one of those places you have to go in, and copy the code every time. (From what I can tell at least).
Especially if you are going to use Private Data Sessions... there is code in this method that is a must! All the global setting in the world won't help, because the Data Environment has its own set of environment variables...
Best Regards,
Scott

Please let me know if this has helped [hammer]
 
I assume that you are using this class as the basis for actual forms (*.scx).

Do your individual forms need to access data in different paths? If not, set your path in your main program. If so, consider opening your tables manually in the form LOAD event instead of using the Data Environment at all. If your form class is set to Private Data Session, all of the tables will automatically close when the form releases since the data environment will also release. However, if you're a stickler for cleaning up your own mess like I am (or have nightmares from C/C++ memory leaks) you can close all of the tables manually in the UNLOAD event.

Hope that helps,

Ian
 
Thanks for your help. Yes, I have a form saved as a class that I am using as my model form. Since I am new to the language, I am going to let the program (Autoopen and Autoclose) the tables. If I opened the files in the Load event, I would still have to change that event each time (for different files). I will copy and paste the BeforeOpenTables code for each form and just select the tables to be included in the DataEnvironment. Maybe the next Foxpro version will have a way to save the DataEnvironment. Thanks again.
 
Hi Kimsue, Scott & Ian,
1. I dont understand the need to specify the data path in Before open tables. Hope I am not making a quick reading and talking something else.
2. To specify the data path.. I do the following in my Main.PRG.
****************************************************
PUBLIC gcDataPath, gcHomeDirectory
gcDataPath = "DATA\" && replace with your data path.
gcHomeDirectory = JUSTPATH(SYS(16,0))
SET DEFAULT TO (gcHomeDirectory)
SET PATH TO SET("PATH")+";"+gcDataPath
****************************************************
This takes care of my data path for all the forms and procedures. There is no need to specify the data path in Data Environment separately.
:)
ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
When you select the tables to be included in the form in the DataEnvironment, the CursorSource contains the path of the files you have selected. Would that (CursorSource) not override the path you set in the main program? I based my code on the suggestion in Q128996 FOXPRO SUPPORT-MICROSOFT. Each installation may have their data stored in a different location. Thanks for your input.
 
HI Kimsue.
The path appearing in the source will not disturb the runtime path specified. The rule I believe is that the table located in the earliest of search path is used by VFP, if not available in the default directory or in the specified place.
SO the correct method is to have the data stored in a DATA directory within the default directory (Data directory name can be a variable in a mem stored in the default directory. So SET PATH will direct to this directory. The same data files shall not be made available in any earlier path.).

This will ensure that no accidents takes place as to the location of the data path.. and where ever installed, the relative path will take care by itself. That is the reason in my code.. I put gcHomeDirectory.
Hope this explains the concern. The FullPath seen in the datasource will be ignored at run time. I have not faced any problem so far in this regard.

:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hi Ramani, I tried placing the code in the startup program and removing my code in the BeforeOpenTables event of the DataEnvironment with no success. One more major piece of information for ya... I can not use a database (YET) as the data files (tables) need to have the ability to be accessed by Foxpro 2.6 programs AND Visual Foxpro programs. Your solution may work with the database, but I don't think it's safe with tables (lot of them). Thanks for your input, though.



 
Hi Kimsue,

Why not subclass the form class (say MyDataForm). Create a method called SetTablePath:

*-- Close your tables
Thisform.DataEnvironment.CloseTables()

*-- Put your code here


*-- Open the tables again
Thisform.DataEnvironment.OpenTables()


Call this method from the Load method. It should do the trick.

Jean


 
Kimsue,
You know, I just had another thought on this... (Some times I get so "caught up" in the newer OOP world...).
A simple solution that is quite viable, is to do this:

Create your form class. (You've done this already).

Create a new form, using your Form Class, but don't actually *put* any objects in it that you wouldn't releady put into your form class. Open the Data Environment, and put in the code you want.

Save the form, but put it some place like CLASSES\BASEFORM

Then, instead of clicking the "New Form" button when you want to creat a new form based on this form, simply copy the form, and rename it. Then, when you open the copy of the form, (which you would then place in FORMS\) you have all of your "Base" elements for the form.

Now, the really clever bit is, because this form was created from you "Form Class", any changes to the Form Class you make will still get inherited in your "Copied" form, and your DE will remain in tact. (It's just the difference between using a "Form Class" and using an actual "Form" that you copy and rename instead.) The benifit of which is, though, you don't have to re-write the code every time. (I used to use this practice all the time in my 2.6 days, by copying a "Like" form anytime I started a new one... That way, I only had to change a few things, and add the appropriate fields to the form. VFP is really no different in that regard).
So, hopefully this, while a kludge, solution would work well for your needs.

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top