Click or drag to resize

FReadLine Function

Read a line from an open file.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax
 FUNCTION FReadLine(
	ptrHandle AS IntPtr,
	nMax AS DWORD
) AS STRING
View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to read from.
nMax
Type: UInt32
The maximum number of characters to read per line.  FReadLine() will read until a hard carriage return (Chr(13)) is reached, end-of-file is encountered,  or <nMax> characters are read.  The default value for <nMax> is 256.

Return Value

Type: String
The line read.  When the end-of-file is reached, FReadLine() returns a NULL_STRING and FError() is set to 257.
Remarks
This function is the same as FGets().  Both functions are assumed to handle raw binary data and are not dependent upon the status of SetAnsi().  FReadText() and FRead4(), on the other hand, are dependent upon SetAnsi().
Remarks
Tip Tip
The low level File IO functions in the X# runtime are using .Net filestreams in the background.
That means that the file handles returned by FOpen() and FCreate() are not 'normal' file handles, but unique identifiers that are used to find the underlying stream object in a collection of streams in the runtime.
That also means that you can't use file handles for functions such as FRead() and FWrite() that were not created in the X# runtime.
If you want to access the underlying FileStream, then you should call the function FGetStream()
Examples
This example uses FReadLine() to read an entire file without specifying a value for <nMax>:
X#
ptrHandle := FOpen2("docs.txt", FO_READ)
IF ptrHandle != F_ERROR
        DO WHILE !FEOF(ptrHandle)
                ? FReadLine(ptrHandle)
        ENDDO
ENDIF
FClose(ptrHandle)
The following example provides a utility that displays and counts all occurrences of a string within a file:
X#
FUNCTION Grep(cSearch, cFile AS STRING) ;
                AS DWORD PASCAL
        LOCAL handle AS PTR
        LOCAL Count AS DWORD
        LOCAL Line AS STRING
        Line := " "
        handle := FOpen2(file, FO_READ)
        cSearch := Upper(cSearch)
        DO WHILE !FEOF(handle)
                line := Upper(FReadLine(handle))
                IF InStr(cSearch, line)
                        ? line
                Count += 1
                ENDIF
        ENDDO
        RETURN Count
See Also