At best you put a relevant path into configuration file, like INI, DBF, XML, whatever, a file within Allusers documents or in the app folder or wherever you can find it by definition without asking the user where your app is installed. As a hint SYS(16,0) is telling you where YOU are, where the exe started is located.
Then you read in a config into a cursor or properties of a global application or configuration object.
That's how you go about anything you may use multiple times. You put a value you may need more than once into a single place and then the problem of needing to change code at mutiple places vanishes and you can do what you now think is bad. It's not at all bad to SET PATH, you can't do it too often. There is no too often.
Your idea is wrong, and your fear is, too, by the way. If the current path is set by SET DEFAULT or CD, then that path is set only code will change it, it doesn't change itself or by starting a new form or a new datasession. The topic on sessions will tell you what environment variables change per session, the current directory is not among that.
There often is a misunderstanding this is a computer scoped thing, your current path is not the current path of application you may automate, so eg word or outlook has no idea of your currrent dir.
But nevertheless programming in a way to depend on an outset always is a bad choice. You will use a third party component or will yourself change path for whatever reason and break your own code. Always program in a way your code may not break, even if other developers or yourself change environment settings such as a path.
Last not least there is SET PATH and you can specify not just one path, but a list of paths, and you can add paths via ADDITIVE. These paths you specify are also searched for DBFs, FRXs or such things outside of your final EXE, and about the EXE you don't need any specific path, eg installation path to a form you call by DO FORM, because foxpro searches inside the EXE first anyway.
Yes, I always do SET PATH just once, at the start of the program. The path will stay in force unless you explicitly change it. You certainly don't need to do it in every form. Nor is it scoped to a data session.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.