xHarbour Reference Documentation > Function Reference |
Opens or closes a text file in a text file area.
HB_FUse( [<cTextfile>], [<nMode>] ) --> nFilehandle
If no parameter is passed, the text file open in the currently selected text file area is closed.
File open modes
Constant | Value | Description |
---|---|---|
FO_READ *) | 0 | Open file for reading |
FO_WRITE | 1 | Open file for writing |
FO_READWRITE | 2 | Open file for reading and writing |
*) default |
Constants that define the access or file sharing rights can be added to an FO_* constant. They specify how file access is granted to other applications in a network environment.
File sharing modes
Constant | Value | Description |
---|---|---|
FO_COMPAT *) | 0 | Compatibility mode |
FO_EXCLUSIVE | 16 | Exclusive use |
FO_DENYWRITE | 32 | Prevent other applications from writing |
FO_DENYREAD | 48 | Prevent other applications from reading |
FO_DENYNONE | 64 | Allow others to read or write |
FO_SHARED | 64 | Same as FO_DENYNONE |
*) default |
The function returns a numeric file handle when the text file is successfully open, or zero on failure.
HB_FUse() opens an existing text file named <cTextfile> in the currently selected text file area. All text file functions operate only in the currently selected text file area. Call HB_FSelect() to change a text file area for opening multiple text files.
The file open in the currently selected text file area is closed when HB_FUse() is called without parameters.
See also: | FOpen(), FSeek(), HB_FLastRec(), HB_FGoto(), HB_FReadLN(), HB_FSkip(), HB_FSelect() |
Category: | File functions , Text file functions , xHarbour extensions |
Source: | misc\hb_f.c |
LIB: | libmisc.lib |
// The example implements a simple text file viewer using a // TBrowse object and text file functions. #include "Common.ch" #include "Inkey.ch" #include "TBrowse.ch" PROCEDURE Main( cFile ) LOCAL nFile, oTBrowse SET CURSOR OFF nFile := HB_FUse( cFile ) IF nFile < 1 ? "File not found", cFile QUIT ENDIF oTBrowse := TxtBrowse() RunTxtBrowse( oTBrowse ) HB_FUse() RETURN PROCEDURE RunTxtBrowse( oTBrowse ) LOCAL nKey, nLen, lRun := .T. DO WHILE lRun oTBrowse:forceStable() nKey := Inkey(0) SWITCH nKey CASE K_LEFT IF oTBrowse:cargo > 1 oTBrowse:cargo -- oTBrowse:refreshAll() ENDIF EXIT CASE K_RIGHT oTBrowse:cargo ++ oTBrowse:refreshAll() EXIT CASE K_HOME IF oTBrowse:cargo > 1 oTBrowse:cargo := 1 oTBrowse:refreshAll() ENDIF EXIT CASE K_END nLen := Len( HB_FReadLN() ) IF nLen-oTBrowse:cargo+1 > 72 oTBrowse:cargo := nLen - 72 + 1 oTBrowse:refreshAll() ENDIF EXIT CASE K_CTRL_HOME EXIT CASE K_CTRL_END EXIT DEFAULT IF oTBrowse:applyKey( nKey ) == TBR_EXIT lRun := .F. ENDIF END ENDDO RETURN FUNCTION TxTBrowse( nT, nL, nB, nR ) LOCAL oTBrowse, oTBCol1, oTBCol2 DEFAULT nT TO 0, ; nL TO 0, ; nB TO MaxRow(), ; nR TO MaxCol() oTBrowse := TBrowseNew( nT, nL, nB, nR ) oTBrowse:cargo := 1 oTBCol1 := TBColumnNew( " ", ; {|| Padr(HB_FRecno(),5)+":" } ) oTBCol2 := TBColumnNew( " ", ; {|| Padr( SubStr( HB_FReadLN(), oTBrowse:cargo), 72 ) } ) WITH OBJECT oTBrowse :addColumn( oTbCol1 ) :addColumn( oTbCol2 ) :goTopBlock := {|| HB_FGotop() } :goBottomBlock := {|| HB_FGoBottom() } :skipBlock := {|n| TxtSkipper(n) } :colPos := 2 END RETURN oTBrowse FUNCTION TxtSkipper( nRequest ) LOCAL nSkip := 0 DO CASE CASE nRequest == 0 CASE nRequest < 0 DO WHILE nSkip > nRequest .AND. HB_FRecno() > 1 HB_FSkip(-1) nSkip -- ENDDO CASE nRequest > 0 DO WHILE nSkip < nRequest HB_FSkip(1) IF HB_FEof() EXIT ENDIF nSkip ++ ENDDO ENDCASE RETURN nSkip
http://www.xHarbour.com