*:
*: MENUS.DFT - dBFast Template File for Menus
*:
*:     Project: <<PROJECT_NAME>>
*:
*:     Program: <<PROG_NAME>>
*: Description: <<DESC>>
*:      Author: <<AUTHOR>>
*:    Copyright <<COPYRITE>>
*:

<<DO WHILE DLLS>>
<<DECLARE_DLL>>
<<ENDDO>>

SET PROCEDURE TO <<PROG_NAME>>
SET PROCEDURE TO <<LIBRARY>>

<<DO WHILE PROC_LIBS>>
SET PROCEDURE TO <<PROC_LIB>> && Set user procedure file
<<ENDDO>>
<<PROC_VALIDS>>


SET EVENTMSK TO 143

SET READ VIDEO TO 240

<<SET_FONTS>>

*: Initialize memory variables
PRIVATE sMenuName, sAction, lOpenDBF
STORE 0  TO nTheMenu, nTheOption, nTheKey
STORE '' TO sTheWindow, sTheButton
STORE .T. TO  lOpenDBF

<<MEM_VARS>>

<<DECLARE_DBF_ARRAY>>

DO <<PROG_NAME>>_DBFSetup

<<DO BEFORE>>

SET WINDOW TITLE TO '<<DESC>>'

<<DO WHILE POPUPS>>
<<CREATE POPUP>>
<<ENDDO>>

<<CREATE PULLDOWN>>

sMenuName = '<<PROG_NAME>>'
SET MENU TO sMenuName

<<MENU_STATES>>

*: Init sAction to something so it is not empty
sAction = '?'

DO WHILE .NOT. EMPTY(sAction)

  READ SAVE

  nEvent     = EVENT()
  nTheMenu   = HMENU()
  nTheOption = VMENU()
  nTheKey    = LASTKEY()
  sTheWindow = WINDOW()
  sTheButton = BUTTON()

  sAction = <<PROG_NAME>>_Translate(nEvent)
  DO <<PROG_NAME>>_Action
ENDDO

sAction = '?'

<<DO AFTER>>

DO <<PROG_NAME>>_DBFClose

ERASE
CLOSE MENU '<<PROG_NAME>>'

RETURN

*****************************
FUNCTION <<PROG_NAME>>_Translate()
*****************************
PARAMETER nTheEvent
PRIVATE sTheAction

  sTheAction = ' '
  DO CASE
	 CASE nTheEvent = eClose
		sTheAction = 'CLOSE'

<<IF KEYS>>
	 CASE nTheEvent = eKybd
		DO CASE
  <<DO WHILE KEYS>>
		  CASE ExactMatch(nTheKey, <<THE_KEY>>)
			 sTheAction = '<<THE_NAME>>'
  <<ENDDO>>
		  OTHERWISE
			 sTheAction = '?'
		ENDCASE
<<ENDIF>>

<<IF MENUS>>
	 CASE nTheEvent = eMenu
	 sTheAction = '?'
		DO CASE
  <<DO WHILE MENUS>>
		  CASE ExactMatch(nTheMenu, <<THE_MENU>>)
			 DO CASE
	 <<DO WHILE OPTIONS>>
				CASE ExactMatch(nTheOption, <<THE_OPTION>>)
				  sTheAction = '<<THE_NAME>>'
	 <<ENDDO>>
			 ENDCASE
  <<ENDDO>>
		ENDCASE
<<ENDIF>>

	 OTHERWISE
		sTheAction = '?'
  ENDCASE
RETURN(sTheAction)


*************************
PROCEDURE <<PROG_NAME>>_Action
*************************

  DO CASE
	 CASE sAction = 'CLOSE'
		sAction = ''

<<DO WHILE ACTIONS>>
	 CASE ExactMatch(sAction, '<<THE_NAME>>')
		<<DO ACTION>>
<<ENDDO>>
  ENDCASE
RETURN


*************************
PROCEDURE <<PROG_NAME>>_DBFSetup
*************************

<<DO WHILE DATAFILES>>
IF FILE("<<DATAFILE>>.DBF")
  FileOpen("<<DATAFILE>>", lOpenDBF)  
  <<IF INDEXES>>
  SET INDEX TO <<INDEXES>>
  <<ENDIF>>
  <<IF FIELDLIST>>
  SET FIELDS TO <<FIELDLIST>>
  SET FIELDS ON
  <<ENDIF>>
  <<IF FILTER>>
  SET FILTER TO <<FILTER>>
  <<ENDIF>>
ELSE
  WARNING(csNoDataFile,"<<DATAFILE>>",387)
  CLOSE WINDOW '<<PROG_NAME>>'
  RETURN
ENDIF
<<ENDDO>>

<<DO WHILE RELATIONS>>
SELECT <<REL_FROM>>
<<DO WHILE LINKS>>
  SET RELATION TO <<REL_EXP>> INTO <<REL_TO>>
<<ENDDO>>
<<ENDDO>>

STORE .F. TO lOpenDBF
RETURN


*************************
PROCEDURE <<PROG_NAME>>_DBFClose
*************************

<<DO WHILE DATAFILES>>
FileClose("<<DATAFILE>>")
<<ENDDO>>

RETURN


*************************
FUNCTION ExactMatch()
*************************
PARAMETERS sVar1, sVar2

	lReturn = .F.
	SET EXACT ON
	lReturn = (sVar1 = sVar2)
	SET EXACT OFF
RETURN(lReturn)
