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

General question about "path" and "include" 2

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
GB
In one of my projects I have the following code in the first part of my main program:

mPath = 'C:\CMWIN, C:\CMWIN\solution, c:\cmwin\foxpro, C:\CMWIN\PRG, C:\CMWIN\SCRN, C:\CMWIN\REPORTS,;
c:\3100, c:\3100\programs, c:\cmwin\search, c:\cmwin\images, C:\djbdemo'

SET PATH TO (mPath)

The directories are whre my sourec code is kept etc...

First
do I need the path to include the directories where
source code is kept
Second
if so what happens if the soiurce code is no
longer on "C:\" drive

Also when I'm using #INCLUDE, I'm directing it to a drive and file. For example #include c:\cmwin\define.h

Do I have to include the drive and directory. If so is it possible to have a variable drv. Once again as my source code is no longer on c:\ drive.

Thanks

 
bebbo

Hard coding of paths can be problematical should you move the project to another drive or folder.
Code:
[COLOR=blue]SET CLASSLIB TO classes\myclasslib ADDITIVE[/color]
will find the folder assuming it be a subfolder of the folder in which your project is contained.


You can save the startup folder early on in an application to a property in a form/object and reference the path with
Code:
[COLOR=blue]THISFORM.Image1.Picture = ADDBS(oMain.cHomeFolder) + [myJpeg.jpg][/color]
should you change drive\folder at any time.

That way it matters not where you put a project as all paths are relative to the project folder.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
Sorry I don't understand. How should I be setting the path and using the "include" feature then. To be honest I've picked this source code up from a previous employee. All my new source code I've done similar to this as I did not know any different.

For example if I'm using the directories above how should I "declare" this???? Without hard coding it.

Thanks

 
bebbo

Put
Code:
[COLOR=blue]_INCLUDE = [Include files\foxpro.h][/color]
in your main.prg, substituting the name of the subfolder of the folder in which your project resides for 'Include files'.

If the application is not structured with 'classes, 'databases', 'tables', 'forms', 'include files', 'reports' etc as being the names of the subfolders of the main app folder, I personally would take the time to structure the app that way and dispense with the path statement.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
bebbo

What I didn't explain was a way of saving the startup drive\path to an object for subsequent use.

If you put the following code early on in the root of your main.prg
Code:
[COLOR=blue]oMainObject = CreateObject([Empty])[/color][COLOR=green] && VFP 8.0[/color][COLOR=blue]
AddProperty(oMainObject,[cHomeFolder],SYS(5) + ADDBS(SYS(2003)))[/color]
you can reference the startup folder as oMainObject.cHomeFolder


FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
My application is structured in the following way:

CMWIN\Projectfile.PJT & .PJX
CMWIN\SCRN\*.scrn
CMWIN\PRG\*.PRG
CMWIN\Reports\*.frx
CMWIN\CLASSES\ (class files)
The source code is kept as above.

I then use tables in \3100 (the drive etc is configure within my main program). Databases are not used.

If I remove my path statement within my main program the "SET Procedure to" commands do not work as the programs cannot be located. Is the setup of this source code incorrect??? If so what do I have to do to correct the problem.

Thanks
 
bebbo

The code for the procedure file would be
Code:
[COLOR=blue]SET PROCEDURE TO prg\myprocedures ADDITIVE[/color]
or
Code:
[COLOR=blue]SET PROCEDURE TO prg\myprocedures.prg ADDITIVE[/color]

The structure you listed will work as all the folders are subfolders of the folder containing the project files, and can be referenced as in the examples given.

If you copy the folder CMWIN plus subfolders to another drive or another folder, you can open the project in its new location, VFP will ask if you wish to make the new location the home for the project, you then recompile the app in the new location and the app will initialize correctly.

The only hard coded path required is to \3100 which you indicated is in your main.prg - alternatively you could use a field in a table to hold the path which would be more flexible should you wish to relocate the tables at any time.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
Bebbo,

In general, it is safe to include hard-coded directories for your source code, provided they are only relevant in the development environment. It doesn't matter if they cannot be found at run time, as your application will have no need to find them.

This is some typical code in my main program:

* Flag to say if we are in EXE or development
glRunTime = (VERSION(2)=0)

...

* Set default directory to the directory holding
* either the main PRG or the EXE
SET DEFAULT TO JUSTPATH(SYS(16))

* If in development, set path (note that these
* are all sub-directories off the default directory)
IF NOT glRunTime
SET PATH TO Code, Classses, Forms, Menus, Reports
ENDIF


Hope this makes sense.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Allo.

I also have a lot of problems with paths. I now use an .INI file, put all the variables paths. In my base custom class, I have one method called .get_privStr() that read the .INI (usually MAIN.INI), and the program set the paths by itself. The .INI file is flat ASCII and easy to modify with notepad.

Here is .get_privStr()

LPARAMETER tcSegment AS String, tcOption AS String, tcIniFile AS String

*** DECLARE DLL statements for reading/writing to private INI files ***
DECLARE INTEGER GetPrivateProfileString IN Win32API AS GetPrivStr ;
String cSection, String cKey, String cDefault, String @cBuffer, ;
Integer nBufferSize, String cINIFile

*** Paths de l'objet ***
lcRetValue = ""
lcBuffer = SPACE(100)
IF GetPrivStr(tcSegment, tcOption, "", @lcBuffer, LEN(lcBuffer), tcIniFile) > 0
lcRetValue = IIF(AT(CHR(0),lcBuffer)#0,LEFT(lcBuffer,AT(CHR(0),lcBuffer)-1),ALLTR(lcBuffer))
ENDIF

RETURN lcRetValue


So, in the MAIN.INI

[devApplication]
pthApp=C:\Apps\custDesspthAppLibs=C:\Apps\custDess\LibspthAppPrg=C:\Apps\custDess\PrgpthAppMessDBF=Message.DBF


You call the method, store the info in a variable and set the paths.


lcPthApp = THIS.get_privStr("devApplication","pthApp","MAIN.INI")

SET PATH TO &lcPthApp

...
Hope it helps

Nro

BTW, you can set installation paths in the .INI file when you create a distributable package with InstallShield.

Bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top