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!

SET DEFAULT

Status
Not open for further replies.

Gotheallblacks

Programmer
Oct 16, 2003
60
NZ
I've forgotten something somewhere. I have a test environment on S: drive and a live one on Z: drive.
I use Private data sessions and in "load Event" of each form I have set default to remotefolder z:\live .I don't have "s:" or "z:" anywhere in any prg,vcx.. etc
the remotefolder var is set from an .ini var (which is correct and tested).

Both databases have the same name.

My problem is my compiled exe on c:\program files\prog.exe looks at s:\test\data\database not at z:\live\data\database which is where it should.

What is strange is that if I rename the s:\test dir to a temporary name and re-run my exe it looks and works correctly at the z:\live\data\database.

I did originally copy and paste the database and tables from S:\test... to z:\live... to set up the live data and then validated the database I'm wondering if there is something obscure leftover from this or I am missing something ?
 
What is strange is that if I rename the s:\test dir to a temporary name and re-run my exe it looks and works correctly at the z:\live\data\database.
Suggests some sort of path problem - if s:\test comes before z:\live in a list of paths somewhere then Fox will use the test database if it exists but go on to find the live database if it doesn't.

Could you dump LIST STATUS to a file from the exe and see what the path and default dir are at runtime?

Geoff Franklin
 
I use Private data sessions and in "load Event" of each form I have set default to remotefolder z:\live

No good. By the time your form gets to the Load event, it will already have processed the data environment and so would already have opened the tables.

One possible solution is to inhibit the opening of tables by the data environment. To do so, set the data environment's AutoOpenTable and AutoCloseTables to .F. Then explicitly open them in the Load, after you have set the path.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike

I had also set default and set path in my main start.prg which I thought I would not have had to set in 'Load event' anyway duplicate code but default set before and during. I'v taken out of the 'Load event' leaving only set default , set path and set database in the start.prg . Same result

Geoff I have dump'd status. Before and during.
both Default dir and path directory's have shown to be correct as z:\live... but I have noticed the the "Current Database z:\live\database closes between my start.prg (b4 running login form) and my login form (BeforeOpenTables event) and yet I have no close or set database cmds in the login form (or anywhere else).

Why would the open database close and go on a search for the tables somewhere else ie finding tables in s:\test as from there on my forms list status show no "Current Database" just open tables.

 
Gotheallblacks,

Setting the default and the path in the main program is a good way to go. You are right that you don't need to do it again in the Load of the form (even if the form has a private data session).

But that doesn't address my main point. It is the data environment that is opening the files. The individual cursors within the DE have a property that includes the full path and file name, as it was when you created the form (s:\test\data\database in your case). That's where they will look first for the files.

Since you can't change that setting, you have to tell the DE not to open the files and do it yourself in the Load (as per my previous suggestion). Did you try that yet?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks for replying Mike

I can see what you mean, just thought that when you set default and open a database and set it to that database it would look for the tables in the open database ist and not use those orig settings. didn't realise it would be closed after using these original form DE settings.

Is it better to move to DE classes or use the form DE I'm using the form DEs currently and would like to know which would be more efficient.

Is there a generic routine for your suggestion else I'll be changing form DEs all the time.??
 
Gotheallblacks,

The answer depends in part on which version you are using. In VFP 7.0 and below, you cannot access the DE at the class level, so you are stuck with a non-generic solution, i.e. labouriously changing it by hand every time (as far as I know; there might be a way of doing it generically, but I have never figured it out).

In 8.0 and above, you can create a DE class and add that to any form. I guess that would be a good way to go. I've not done that myself yet, so I can't give you any more details, but it should be pretty straightforward.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi all,

it was either the Hacker's Guide or 1001 Things You Always Wanted To Know... there is code to generically change the database paths of the cursor objects of the DE. The general idea is to do this in the BeforeOpenTables Event of the DE and to instanciate a generic class there, that loops through the cursor object and translates the paths...

Another general idea is to use the OpenTables Event and open the tables in there with USE Tablealias IN 0 ... and set relations with SET RELATION TO...

Bye, Olaf.
 
Olaf,

The general idea is to do this in the BeforeOpenTables Event of the DE and to instanciate a generic class there, that loops through the cursor object and translates the paths...

Yes, I remember seeing that code in KiloFox. But as far as I remember (I don't have the book in front of me), it does not do it at the class level, so it's not generic. The code had to be written in the DE at the form level, simply because KiloFox came out while 6.0 was current, and DE classes were only introduced in 8.0.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Well as a newbie I guess its another trap.

I looked further by hacking the form scx (copied first) and I could not see where it sets the drive in the properties. It only has "Database = ..\data\database.dbc" and the cursor,relation etc filename only , no path.

Are the drive properties set somewhere else. Because from this I would think that it would come from setting default!
 
If you only see a relative path, that is because the database is in the project folder, isn't it?

At runtime foxpro would look relative from the exe's path one up, seach a data dir and the database inside that - and will most probably fail, because in run time environment the database is somewhere else, right?

To Mike: You're right, that yoou have to modify each scx, but I think the class in KiloFox was programmed in a way, that you'd only need to add a CREATEOBJECT(...) in each scx's DE BeforeOpenTables Event, which is rather generic...

Bye, Olaf.
 
Olaf

Hmm Just trying to get this clear in my head. So when compiling to exe onto c: drive c:\program files\programs it is picking up the original dataenivironment of the form from project dir on S: drive and holding that s:\test\data path in the exe and if it doesn't find the data there it then uses the default settings which have been set to z:\live\data ?

Andrew
 
Hi Andrew,

You say you're having paths ..\data\database.dbc in the cursor objects of the data environment, right?

Let me guess you have (among others) these folder structure for your project:

s:\myproject\myproject.pjx
s:\myproject\forms - all scx files stored here
s:\myproject\data - database here.

That would explain that relative path to the database.
Now if you compile the exe it will be in the folder
s:\myproject\myproject.exe

And when running a from in the exe, that would look from the current dir up one folder and look for databse.dbc in a data folder. If it doesn't find it there look in what's set in PATH or DEFAULT..., the help has that search order explained somewhere. If you set the current dir (==DEFAULT) with CD, the search will start from there, so depending on that the exe may or may not find the test data instead of the live data.

To make sure the exe uses the live data, you should change that paths at runtime to the correct dir anyway.

Bye, Olaf.
 
Olaf

Not quite right my EXE is compiled to c:\program files\programs.
s:\myproject\myproject.pjx (yes)
s:\myproject\forms - all scx files stored here (yes)
s:\myproject\data - database here (yes)

When I build to an EXE I put it in the C:\program files\programs
I have an .INI file in C:\program files\programs which has a var in it "remotefolder=Z:\live" which is picked up by the EXE to set default(tested and working).

I have an Shortcut on the desktop it points to the EXE in this directory and Start in is set to this as well. Thats what I don't understand it doesn't seem logical for the EXE on a C:drive looking at the S:test when its default is set to look in Z:.

If I rename the "s:\myproject" to say s:\temp and run my C:\program files\EXE it will correctly look at the z:\live

 
Although this is quite unlikely, maybe the relative paths in the DE change to absolute paths during compile to C:\program files\programs. You could test and compile to s:\myproject\myproject.exe instead.

More likely is, that the paths may be displayed as if being relative paths, but internally really are the full paths. That would explain, why the DE still is opening the data in s:\test. You may check that, when you copy your whole project to another drive, then the paths within the DE should point to s:\test\...

All in all, the DEFAULT path is not the first path foxpro looks. So the idea of changing the paths in the DEs BeforeOpenTables Method is still the way to go.

Bye, Olaf.
 
Olaf

Well compiling to the project dir b4 copying worked.

I Compiled to s:\myproject\project.exe

Then COPIED to c:\program files\project.exe and it now points correctly to z:\live\data when running.

So it was in the compiling storing absolute path.

I started using DE classes but I don't see any benefits of using them yet except for pointing to non VFP data. (I might use them eventually)

Thanks Olaf for pointing me to this little trap, saved me a bundle of work on having DE class methods Yuk.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top