setup.prg

来自「MSComm控件资料,Visual Basic 6.0(以下简称VB) 是一种功」· PRG 代码 · 共 891 行 · 第 1/2 页

PRG
891 行
字号
*) This function ...
*) 1. Sets the application's PATHs
*) 2. Builds and executes the SET CLASSLIB TO command thereby
*) setting the application's class libraries
*) 3. Builds and executes the SET PROCEDURE command thereby
*) setting the application's procedure files.
*
*@ Inputs:
*@ 1. CBMeta file - contains all of the procedures
*@ and visual class libraries included in the project.
*@ This is the information needed to execute the
*@
*
* Outputs: None
*
*$ Usage: SETPATH()
*
*% Example:
* IF SetPath()
* goApp.Do()
* ENDIF
*
* Returns: LOGICAL
* 1. .T. if PATH, CLASSLIB and PROCEDUREs could be set
* 2. .F. CBMeta file could not be found .
*
* Assumptions:
* 1. Codebook's default directory structure is obeyed ...
* namely the \PROGS directory contains the MAIN.PRG.
*
* Rules: None
* Constraints:
* Performance: None
* Enviornmental: None
*? Notes: None
* Local Routines: None
*-- Process:
*-- 1. Define local variables.
*-- 2. Determine the name of the calling program ...
*-- this is used to find out the application's path.
*-- 3. Strip the path out of the filename and change to
*-- the applciation's main directory. Note: if the
*-- application is being called from the .FXP the
*-- main directory is one level back ... assuming the
*-- .FXP is properly located in the \PROGS directory.
*-- 4. SET the paths to Codebook's default directory structure.
*-- 5. If in debug mode, build the application's metadata.
*-- 6. If the CBMeta file could not be found ... bug out.
*-- 7. Open the CBMeta file and create the stings that
*-- will be used to execute the SET CLASSLIB and SET PROC
*-- commands.
*-- 8. SET the application's class libraries
*-- 9. SET the application's procedure files
*
* Change Log:
* CREATED Sunday, 10/29/95 15:36:19 - CTB:
************************************************************
FUNCTION SetPath()

	LOCAL lcSys16, lcProgram, lcClassLibs, lcProcs, lcName

	* LOCAL/PRIVATE VARIABLE DESCRIPTIONS
	* --------------------------------------------------
	* lcSys16 - stores the full path and name of the program
	* that called this one.
	* lcProgram - stores the drive, path and name of the
	* executing program?
	* lcClassLibs - stores a string identifying all of the
	* application's Class Libraries
	* lcProcs - stores a string identifying all of the
	* applications procedure files.
	* lcName - stores the name of the class library
	* or procedure file to be added to the
	* command line.

	*-- Grab name of program that called this one.
	lcSys16 = SYS(16, 1)
	lcProgram = SUBSTR(lcSys16, AT(":", lcSys16) - 1)

	*-- Change to the application's main directory
	*-- by stripping the drive and directory information
	*-- out of the filename.
	CD LEFT(lcProgram, RAT("\", lcProgram))

	*-- If we are running MAIN.PRG directly, then
	*-- CD up to the Parent directory. See Assumption
	*-- number one.
	*-- IF RIGHT(lcProgram, 3) = "FXP"
	*-- CD ..
	*-- ENDIF
	*-- Modification: 08/26/1997 08:19:00 - CTB: added function
	*-- call that fixes problems with the CD .. command
	*-- CDToParentDirectory() located in the UTILITY.PRG
	*** EGL: 12/29/1999 - Added the "ADDITIVE" keyword
	*** EGL: 9/20/2000 - reformatted the line below to compile properly
	SET PROCEDURE TO (COMMONPATH + "\PROGS\UTILITY.PRG") ADDITIVE
	IF RIGHT(lcProgram, 3) = "FXP"
		CDToParentDirectory()
	ENDIF

	SetUserDefinedPath()

	*-- Check to see if the application is being run
	*-- in debug mode ... if it is build/rebuild the
	*-- application's metadata.
	IF FILE(DEBUGMODEFILE)
		BuildMetaData()
	ENDIF

	*-- If the metadata file does not exist the setup
	*-- cannot be completed ... the classlib and
	*-- procedure file info is contained in this file.
	IF !FILE(METAPATH + METADATA_TABLE)
		?? CHR(7)
		MESSAGEBOX("Could not find " + METAPATH + METADATA_TABLE + ". Cannot continue.", ;
			MB_ICONEXCLAMATION, APPNAME_LOC)
		RETURN .F.
	ENDIF

	*-- Open the metadata file and select it.
	USE METAPATH + METADATA_TABLE IN 0 ALIAS _metadata
	SELECT _metadata
	STORE "" TO lcClassLibs, lcProcs, lcName

	*-- Build the string that identifies the list of
	*-- visual class libraries ("V") and procedure files ("P")
	SCAN
		lcName = LEFT(name, LEN(name) - 1)
		DO CASE
			CASE type = "V"
				lcClassLibs = lcClassLibs + "[" + lcName + "],"

			CASE type = "P"
				lcProcs = lcProcs + "[" + lcName + "],"

		ENDCASE
	ENDSCAN

	*-- Close the metadata file
	USE

	*-- Trim the commas off of the end of the strings
	lcClassLibs = LEFT(lcClassLibs, LEN(lcClassLibs) - 1)
	lcProcs = LEFT(lcProcs, LEN(lcProcs) - 1)

	*-- Set the application's class libraries and procedure files.
	SET CLASSLIB TO
	SET CLASSLIB TO &lcClassLibs
	SET PROC TO
	SET PROC TO &lcProcs

	RETURN
ENDFUNC


FUNCTION SetUserDefinedPath()
	*-- Description:
	*-- This is an enhancement to Codebook by SAVI that
	*-- allows a developer to customize an application's path.
	*-- The table, SETPATH.DBF in the CBMeta directory
	*-- provides a place for the developer to place this
	*-- information.
	LOCAL lcPath, lnSelect, lcDeveloperSpecifiedPath, llOK2Close

	lcPath = ""

	*-- Set the paths to Codebook's default directory structure.
	*!*	SET PATH TO PROGS, FORMS, LIBS, MENUS, DATA, OTHER, REPORTS, INCLUDE, ;
	*!*		HELP, GRAPHICS, COMMONPATH\UTILS, COMMONPATH\INCLUDE, ;
	*!*		COMMONPATH\UTILS\MSGSVC
	lcPath = [PROGS, FORMS, LIBS, MENUS, DATA, OTHER, REPORTS, INCLUDE, ] + ;
		[HELP, GRAPHICS, ] + COMMONPATH + [\UTILS, ] + COMMONPATH + [\INCLUDE, ] + ;
		COMMONPATH + [\UTILS\MSGSVC]
	SET PATH TO (lcPath)

	*-- Tack on the path specified by the developer
	lcDeveloperSpecifiedPath = ALLTRIM(DEVELOPER_SPECIFIED_PATH)

	*-- Tack on any paths in the DBPATHS table (if it exists)
	IF FILE("DBPATHS.DBF")
		lnSelect = SELECT(0)

		IF USED("DBPaths")
			SELECT DBPaths
			llOK2Close = .F.
		ELSE
			SELECT 0
			USE DBPaths AGAIN SHARED
			llOK2Close = .T.
		ENDIF

		SCAN
			IF lLocalData
				lcDeveloperSpecifiedPath = lcDeveloperSpecifiedPath + [, ] + ;
					ALLTRIM(DBPaths.cdb_local)
			ELSE
				lcDeveloperSpecifiedPath = lcDeveloperSpecifiedPath + [, ] + ;
					ALLTRIM(DBPaths.cdb_remote)
			ENDIF
		ENDSCAN

		IF llOK2Close AND USED("DBPaths")
			USE IN DBPaths
		ENDIF

		SELECT (lnSelect)
	ENDIF

	*-- Set the path accordingly
	lcOldPath = SET("PATH")
	lcNewPath = ["] + lcDeveloperSpecifiedPath + [, ] + lcOldPath + ["]
	SET PATH TO (lcNewPath)

	RETURN
ENDFUNC


************************************************************
* FUNCTION: BuildMetadata()
*
*) Description:
*) Creates a metadata file in the specified metadata
*) directory that contains a list of all procedure files
*) and visual class libraries included in the project.
*) This information is used by the codebook framework
*) to build the proper SET PROC TO and SET CLASSLIB TO
*) commands.
*
*@ Inputs:
*@ 1. APPINCL.H
*@ a. PJX_NAME - stores the name of the project file.
*@
*@ 2. FRAMEWRK.H
*@ a. METADATA_TABLE - stores the name of the metadata file.
*@ b. METAPATH - stores the path to the metadata file.
*@
*@ 3. Application's project file ... identified by PJX_NAME
*@
* Outputs:
* 1. Metadata file containing a list of all
* procedure files (TYPE = "P") and visual class
* libraries (TYPE = "V") present in the project.
*
*$ Usage/Example: =BuildMetadata()
*
* Returns: LOGICAL .T. by default
*
* Assumptions:
* 1. The following include files are available:
* a. FRAMEWRK.H
* b. APPINCL.H
*
* Rules: None
*
* Constraints:
* Performance: None
* Enviornmental: None
*
*? Notes:
*? The metadata file is created/recreated only when the
*? application is in debug mode.
*
* Local Routines: None
*
*-- Process: TBCL
*-- 1. Define local memory variables
*-- 2. IF the project file does not exist ... bug out.
*-- 3. Create an alias for the metadata file.
*-- 4. Delete the metadata file if it exists.
*-- 5. Extract all of the procedure and visual class
*-- library files present in the project.
*-- 6. Store them to the new metadata file.
*-- 7. Exit
*
* Change Log:
* CREATED Sunday, 10/29/95 16:32:36 - CTB:
*		MODIFIED Friday, 09/18/1998 10:27:00 - CTB:
*		As per Dan Welter's suggestion, the code that
*		deletes the metadata table is moved AFTER the
*		code that tries to open the project file. This
*		way, the metadata table is not deleted before
*		we have access to the project ... which we need
*		to rebuild meta. Previously, the metatable was
*		deleted first, then the project file was used.
*		If you didn't get the project file opened, your
*		metadata table was deleted and it couldn't be
*		rebuilt.
************************************************************
FUNCTION BuildMetaData()
	LOCAL lcMetaAlias

	*-- LOCAL VARIABLE DESCRIPTIONS
	*--------------------------------------------------
	*-- lcMetaAlias - stores the alias for the metadata file

	*-- If the project file does not exist ... bug out.
	*-- This is the input file for this function.
	IF !FILE(PJX_NAME)
		RETURN
	ENDIF

	*-- Create an alias for the metadata file based upon
	*-- the name of the metadata file.
	IF "." $ METADATA_TABLE
		lcMetaAlias = LEFT(METADATA_TABLE, AT(".", METADATA_TABLE) - 1)
	ELSE
		lcMetaAlias = METADATA_TABLE
	ENDIF

	*-- Suggestion made by Dan Welter. Try to use the project
	*-- *before* the metadata table is deleted. If the project
	*-- cannot be opened then RETURN out of the function
	*-- before the metadata table is deleted
	USE(PJX_NAME) AGAIN ALIAS _project
	IF NOT USED("_project")
		RETURN
	ENDIF

	*-- Delete the metadata file if it exists.
	IF FILE(METAPATH + METADATA_TABLE)
		*-- Close meta data if user has it open
		IF USED(lcMetaAlias)
			USE IN (lcMetaAlias)
		ENDIF

		*-- Delete the old metadata file and its corresponding .FPT file.
		*-- The reason for this is that the VCX's and PROGRAMS included
		*-- in the project are dynamic and can change from execution
		*-- to execution. This ensures that any new libraries and
		*-- programs added to the project since the program was last run
		*-- in debug mode will be included in the path and classlib settings.
		ERASE METAPATH + METADATA_TABLE
		ERASE METAPATH + STRTRAN(METADATA_TABLE, "DBF", "FPT")
	ENDIF


	*-- Extract all of the non-excluded procedure and visual class
	*-- library files present in the project.
	SELECT Name, Type ;
		FROM _project ;
		WHERE !DELETED() ;
		AND Exclude = .F. ;
		AND (Type = "V" OR Type = "P") ;
		ORDER BY Type ;
		INTO CURSOR cTemp

	*-- Create the metadata file in the specified directory.
	COPY TO METAPATH + METADATA_TABLE
	USE IN _project
	USE IN cTemp

	RETURN
ENDFUNC


*******************************************************************
* FUNCTION: GetString()
*
*) Description:
*) Returns a string from the specified table (tcAlias) with the
*) specified key (tcKey)
*
*@ Inputs:
*@ 1. tcKey - the key that identifies the string stored in
*@ the specified table.
*@ 2. tcAlias - name of the table in which to perform the
*@ string search.
*@
* 3. The table specified in the tcAlias parameter
*
* Outputs: None
*$ Usage:
*$ =GetString(<tcKey>,<tcAlias>)
*
*% Example:
*% =GetString("PJX_NAME", "appincl") - returns the string in the
*% APPINCL.DBF identified by the key "PJX_NAME".
*%
*
* Returns: CHARACTER
* 1. Specified character string ... if it was found.
* 2. Empty string if not.
*
* Assumptions:
* 1. The file specified by <tcAlias> exists.
*
* Rules:
* 1. The alias specified in <tcAlias> must equal the
* first eight characters of the file containing the
* string to find.
* 2. There is a field named "key" in the file that contains
* the unique identifier for the string to return.
* 3. There is a field named "string" in the file that contains
* the actual string to return.
* 4. The file has a compound index tag named "key" that orders
* the lookup table by the "key" field.
*
* Constraints:
* Performance: None
* Enviornmental: None
*? Notes: None
* Local Routines: None
*-- Process:
*-- 1. Save old work area.
*-- 2. Validated <tcAlias> parameter.
*-- 3. Open the file to search.
*-- 4. Search the file for the specified string.
*-- 5. Return the string if found.
*
* Change Log:
* CREATED Sunday, 10/29/95 17:50:51 - CTB:
************************************************************
FUNCTION GetString(tcKey, tcAlias)

	LOCAL lcAlias, lnSelect, lcRetVal
	* LOCAL/PRIVATE VARIABLE DESCRIPTIONS
	*---------------------------------------------------------
	* lcAlias - alias of the lookup table ... defaults to
	* "strings" if none provided.
	* lnSelect - number of the work area selected prior to
	* calling this function.
	* lcRetVal - string retrieved from the lookup table

	*-- Save the old work area
	lnSelect = SELECT(0)

	*-- Validate the tcAlias parameter ... default it to "strings"
	*-- if not provided.
	lcAlias = IIF(PCOUNT() < 2, "strings", tcAlias)

	*-- Open the specified lookup table and select it.
	IF !USED(lcAlias)
		USE (lcAlias) IN 0 NOUPDATE AGAIN SHARED
	ENDIF
	SELECT (lcAlias)

	*-- Lookup the specified string.
	lcRetVal = LOOKUP(string, tcKey, key, "key")

	*-- Reselect the old work area
	SELECT (lnSelect)

	RETURN lcRetVal
ENDFUNC

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?