home *** CD-ROM | disk | FTP | other *** search
- // Tb31.prg
- //
- // Browsing database file names and their structures
- // Version 1. Problem with this version is it redraws the structures
- // even if same database. See Tb311.prg for optimized version
-
- #include "Inkey.ch"
- #include "Dbstruct.ch"
- #include "Directry.ch"
- #include "Tbutils.ch"
-
- FUNCTION Tb31
-
- LOCAL aFiles := Directory("*.dbf")
- LOCAL aStru
- LOCAL nKey
-
- // The TBrowse object to display the DBF file names
- LOCAL oTbrFiles
-
- // The TBrowse object to display the current DBF's structure
- LOCAL oTbrStrus
-
- LOCAL lExitRequested := .F.
-
- SET CURSOR OFF
- SetColor("W+/N,N/W")
- CLEAR SCREEN
-
- oTbrFiles := TBaH2dBrw(aFiles, ;
- {"Name", " Size", ;
- "Date", "Time", "Attr"})
-
- oTbrFiles:colSep := DEF_CSEP
- oTbrFiles:headSep := DEF_HSEP
- oTbrFiles:nTop := 1
- oTbrFiles:nLeft := 1
- oTbrFiles:nBottom := MaxRow() - 1
- oTbrFiles:nRight := 39
- TBFrame(oTbrFiles)
-
- DO WHILE !lExitRequested
- FullStabilize(oTbrFiles)
- USE (aFiles[oTbrFiles:cargo, F_NAME])
- aStru := DbStruct()
- CLOSE (aFiles[oTbrFiles:cargo, F_NAME])
- oTbrStrus := TBaH2dBrw(aStru, ;
- { "Name", "Type", ;
- " Len", " Dec" })
-
- oTbrStrus:colSep := DEF_CSEP
- oTbrStrus:headSep := DEF_HSEP
- oTbrStrus:nTop := 1
- oTbrStrus:nLeft := 42
- oTbrStrus:nBottom := MaxRow() - 1
- oTbrStrus:nRight := 78
- TBFrame(oTbrStrus)
-
- FullStabilize(oTbrStrus)
- oTbrStrus:deHilite()
-
- nKey := InKey(0)
- IF !Stdmeth(nKey, oTbrFiles)
- DO CASE
- CASE nKey == K_ESC
- lExitRequested := .T.
- ENDCASE
- ENDIF
- ENDDO
-
- RETURN NIL
-
-
- FUNCTION TBFrame(oTbr)
-
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO oTbr:nBottom + 1, oTbr:nRight + 1
-
- RETURN NIL
-
-
- // As TBa2dBrw but allows headings. Column width is set to the larger
- // of the heading and the data width
-
- FUNCTION TBaH2dBrw(aVar, aHeadings)
-
- LOCAL oTbr := TBrowseNew()
- LOCAL nCols := Len(aVar[1])
- LOCAL i
- LOCAL oTbc
-
- oTbr:cargo := 1
- oTbr:goTopBlock := {|| oTbr:cargo := 1 }
- oTbr:goBottomBlock := {|| oTbr:cargo := Len(aVar) }
- oTbr:skipBlock := ARRAY_SKIPPER(oTbr:cargo, aVar)
-
- FOR i := 1 TO nCols
- oTbc := TBColumnNew(aHeadings[i], A2DBlock(oTbr, aVar, i))
- // Find width for column here ...
- oTbc:width := Max(A2dWidth(aVar, i), Len(aHeadings[i]))
- oTbr:addColumn(oTbc)
- NEXT
-
- RETURN oTbr
-
-
- FUNCTION A2dBlock(oTbr, aVar, nCol)
-
- RETURN {|| aVar[oTbr:cargo, nCol] }
-
-
- FUNCTION A2dwidth(aVar, nCol)
-
- LOCAL i
- LOCAL nLen := Len(aVar)
- LOCAL nLongest := 0
-
- FOR i := 1 TO nLen
- nLongest := Max(nLongest, DataLen(aVar[i, nCol]))
- NEXT
-
- RETURN nLongest
-
-
- FUNCTION DataLen(xElem)
-
- LOCAL nLen
- LOCAL cType := ValType(xElem)
-
- DO CASE
- CASE cType $ "ACM"
- nLen := Len(xElem)
-
- CASE cType == "N"
- nLen := Len(Str(xElem))
-
- CASE cType == "L"
- nLen := 1
-
- CASE cType == "D"
- nLen := 8
-
- CASE cType == "U" // Value NIL
- nLen := 3
- ENDCASE
-
- RETURN nLen