home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CLIPB52.ZIP / SCHINKEL.ZIP / DBFHAND.PRG < prev    next >
Encoding:
Text File  |  1990-05-17  |  2.5 KB  |  78 lines

  1. /* DBFHAND.PRG - Functions for storing and maintaining the DBF handle.
  2.  
  3.    This file contains DBFHAND() which, when used in conjunction with
  4.    the other functions (and they are used correctly) will return the
  5.    DBF for the currently selected area. It will return -1 if there is
  6.    not a database open in the currently selected area.
  7.  
  8.    The other functions __DBFHANDGRAB(), __DBFHANDLETGO(), and
  9.    __DBFHANDALLGONE() are to be used in the user defined commands of
  10.    USE, CLOSE, and CLEAR ALL. They are called in DBFHAND.CH. Note: All
  11.    files MUST include DBFHAND.CH in a system that uses DBFHAND() even
  12.    if the file does not call DBFHAND(). This file modifies the
  13.    commands above and this is why they MUST be included.
  14.  
  15.    SWITCHES: /n /m /w
  16.  
  17.    REQUIRES: DBFHAND.CH, ASCANNIL.PRG
  18.  
  19.    Copyright (c) 1990; The DSW Group, Ltd.
  20. */
  21.  
  22.  
  23. STATIC aDbfList:= {}
  24.  
  25. #define AreaNo(a)       a[1]
  26. #define AreaHand(a)     a[2]
  27. #define FindFree()      AScanNil(aDbfList)
  28.  
  29. //...........................................................
  30. STATIC FUNC FindElement()
  31. LOCAL nEle:= 0
  32.    IF (Len(aDbfList)>0)
  33.       nEle:= AScan(aDbfList,{|e| IIf(ValType(e)=="A",AreaNo(e)==Select(),.F.)})
  34.    ENDIF
  35. RETURN (nEle)
  36.  
  37. //...........................................................
  38. FUNC DbfHand()
  39. LOCAL nHand:= -1, nEle := FindElement()
  40.    IF (nEle>0).AND.(Len(aDbfList)>0)
  41.       IF (ValType(aDbfList[nEle])=="A")
  42.          nHand:= AreaHand(aDbfList[nEle])
  43.       ENDIF
  44.    ENDIF
  45. RETURN (nHand)
  46.  
  47. //...........................................................
  48. PROC __DbfHandGrab()
  49. LOCAL nEle:= FindElement(),;
  50.       nHand,aEle
  51.    FClose(nHand:= FOpen("NUL",0))      // Get the Next Available Handle
  52.    aEle:= { Select(), nHand }          // Create a structure
  53.    IF (nEle==0)                        // SELECT area not already listed
  54.       IF (nEle:= FindFree())==0        // No free elements
  55.          AAdd(aDbfList,NIL)            // Add a new element
  56.          nEle:= Len(aDbfList)          // Get it's element number
  57.       ENDIF
  58.    ENDIF
  59.    aDbfList[nEle]:= aEle               // Store that element
  60. RETURN
  61.  
  62. //...........................................................
  63. PROC __DbfHandLetGo()
  64. LOCAL nEle
  65.    IF (nEle:= FindElement())>0
  66.       aDbfList[nEle]:= NIL
  67.    ENDIF
  68. RETURN
  69.  
  70. //...........................................................
  71. PROC __DbfHandAllGone()
  72.    aDbfList:= {}
  73. RETURN
  74.  
  75. //...........................................................
  76. // EOF: DBFHAND.PRG
  77.  
  78.