Here is the code I use in each system.
My main program calls cpsetpath.prg
Each workstation has a dbf call cpwsconfig.dbf
In this table, I have a field which stores the path to the main networked folder, for example, \\pos2\appname\databasesI have a cpsetup.exe on each workstation which calls a form that allows the user to edit this field and more.
Also, notice that the cpsetpath.prg program checks for the required folders. So on my development computer the path would be set because those
folders exist, but not on the workstation computers.
I just like working with dbf tables over INI files because I find them easily to program and for users to make changes.
Here is my basic structure...
*-- CPMAIN.prg
clear all
close all
set talk off
local llret
llret = .f.
DO CPSETPATH with llret && sets path for the entire system - see below
if not llret
=messagebox("Could not set path...etc.",16,_screen.caption)
quit
endif
DO CPREGCHECK && checks for workstation registration
DO CPLOADENV && loads cp environment
DO FORM CPMENU && do the main form
READ EVENTS
DO CPCLOSE && close environment
RETURN
*--========================================================================================= CPSETPATH.prg
*-- cpsetpath.prg
*-- Last Edited: 02/21/2013
*-- Sets the path for the system.
parameters llret
CLOSE ALL
IF NOT FILE("cpwsconfig.dbf",1) && this file must be present on the client computer in the folder where the .exe starts.
=MESSAGEBOX("Error locating workstation configuration table (cpwsconfig.dbf). System cannot continue!",16,_screen.caption)
RETURN llret
ENDIF
SELECT * FROM cpwsconfig INTO CURSOR _setpath && get workstation info
IF USED('_setpath')
LOCAL lcbasepath,lcnetpath
lcbasepath = SYS(5)+SYS(2003) && return the start drive/directory
SET PATH TO (lcbasepath)
*-- Set path to the main CP databases - Does not need '\' in the subfolder.
lcnetpath = Alltrim(_setpath.path_cpdbc)
SET PATH TO ','+lcnetpath+'database' additive && for the main CP DBC files
SET PATH TO ','+lcnetpath+'labels' additive && for any shared labels
SET PATH TO ','+lcnetpath+'reports' additive && for any shared reports
*-- Reports and labels Path - Must include '\' for subfolder
IF DIRECTORY('reports',1)
SET PATH TO ','+(lcbasepath)+'\reports' additive
ENDIF
IF DIRECTORY('labels',1)
SET PATH TO ','+(lcbasepath)+'\labels' additive
ENDIF
*-- SET PATH FOR DEVELOPER ENVIRONMENT
*-- Forms Path
IF DIRECTORY('forms',1)
SET PATH TO ','+(lcbasepath)+'\forms' additive
ENDIF
*-- Library Path
IF DIRECTORY('library',1)
SET PATH TO ','+(lcbasepath)+'\library' additive
IF DIRECTORY('library\classes',1)
SET PATH TO ','+(lcbasepath)+'\library\classes' additive
ENDIF
ENDIF
*-- Shared library folder for all systems.
IF DIRECTORY('C:\CP_Library',1)
SET PATH TO ','+'C:\CP_Library' additive
SET PATH TO ','+'C:\CP_Library\graphics' additive
SET PATH TO ','+'C:\CP_Library\forms' additive
SET PATH TO ','+'C:\CP_Library\classes' additive
SET PATH TO ','+'C:\CP_Library\prgs' additive
SET PATH TO ','+'C:\CP_Library\reports' additive
SET PATH TO ','+'C:\CP_Library\utils' additive
SET PATH TO ','+'C:\CP_Library\apps' additive
SET PATH TO ','+'C:\CP_Library\sounds' additive
SET PATH TO ','+'C:\CP_Library\programs' additive
SET PATH TO ','+'C:\CP_Library\cpdocuments' additive
ENDIF
*-- Path to CatalogPro Images
IF DIRECTORY(ALLTRIM(_setpath.path_cpimg))
SET PATH TO ','+ALLTRIM(_setpath.path_cpimg) additive
ELSE
UPDATE cpwsconfig SET path_cpimg = ""
ENDIF
* close setpath cursor
USE IN _setpath
ELSE
=MESSAGEBOX("Error initializing cpwsconfig cursor in cpsetpath.prg!"+chr(13)+chr(13)+"CatalogPro cannot continue!",16,_screen.caption)
RETURN llret
ENDIF
CLOSE TABLES all
* CLOSE DATABASES all
llret = .t.
RETURN llret