home *** CD-ROM | disk | FTP | other *** search
- /* DBFHAND.PRG - Functions for storing and maintaining the DBF handle.
-
- This file contains DBFHAND() which, when used in conjunction with
- the other functions (and they are used correctly) will return the
- DBF for the currently selected area. It will return -1 if there is
- not a database open in the currently selected area.
-
- The other functions __DBFHANDGRAB(), __DBFHANDLETGO(), and
- __DBFHANDALLGONE() are to be used in the user defined commands of
- USE, CLOSE, and CLEAR ALL. They are called in DBFHAND.CH. Note: All
- files MUST include DBFHAND.CH in a system that uses DBFHAND() even
- if the file does not call DBFHAND(). This file modifies the
- commands above and this is why they MUST be included.
-
- SWITCHES: /n /m /w
-
- REQUIRES: DBFHAND.CH, ASCANNIL.PRG
-
- Copyright (c) 1990; The DSW Group, Ltd.
- */
-
-
- STATIC aDbfList:= {}
-
- #define AreaNo(a) a[1]
- #define AreaHand(a) a[2]
- #define FindFree() AScanNil(aDbfList)
-
- //...........................................................
- STATIC FUNC FindElement()
- LOCAL nEle:= 0
- IF (Len(aDbfList)>0)
- nEle:= AScan(aDbfList,{|e| IIf(ValType(e)=="A",AreaNo(e)==Select(),.F.)})
- ENDIF
- RETURN (nEle)
-
- //...........................................................
- FUNC DbfHand()
- LOCAL nHand:= -1, nEle := FindElement()
- IF (nEle>0).AND.(Len(aDbfList)>0)
- IF (ValType(aDbfList[nEle])=="A")
- nHand:= AreaHand(aDbfList[nEle])
- ENDIF
- ENDIF
- RETURN (nHand)
-
- //...........................................................
- PROC __DbfHandGrab()
- LOCAL nEle:= FindElement(),;
- nHand,aEle
- FClose(nHand:= FOpen("NUL",0)) // Get the Next Available Handle
- aEle:= { Select(), nHand } // Create a structure
- IF (nEle==0) // SELECT area not already listed
- IF (nEle:= FindFree())==0 // No free elements
- AAdd(aDbfList,NIL) // Add a new element
- nEle:= Len(aDbfList) // Get it's element number
- ENDIF
- ENDIF
- aDbfList[nEle]:= aEle // Store that element
- RETURN
-
- //...........................................................
- PROC __DbfHandLetGo()
- LOCAL nEle
- IF (nEle:= FindElement())>0
- aDbfList[nEle]:= NIL
- ENDIF
- RETURN
-
- //...........................................................
- PROC __DbfHandAllGone()
- aDbfList:= {}
- RETURN
-
- //...........................................................
- // EOF: DBFHAND.PRG
-