Click or drag to resize

FRead Function

X#
Read characters from a file into a buffer variable that is passed by reference.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION FRead(
	ptrHandle AS IntPtr,
	cBufferVar REF STRING,
	dwBytes AS DWORD
) AS DWORD
Request Example View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to read from.
cBufferVar
Type: String
A variable used to store data read from the specified file.
If the length of cBufferVar is less than dwBytes, a new string whose length is the minimum of dwBytes and the remaining bytes in the file is allocated. cBufferVar must be passed by reference and, therefore, must be prefaced by the pass-by-reference operator (@).
dwBytes
Type: DWord
The number of bytes to read into the buffer.

Return Value

Type: DWord
The number of bytes successfully read.
A return value less than dwBytes or 0 indicates end-of-file or some other read error. FError() can be used to determine the specific error.
Remarks
FRead() reads from the file starting at the current DOS file pointer position, advancing the file pointer by the number of bytes read.
All characters are read, including control, null, and high-order (above Chr(127)) characters. FRead() is similar in some respects to both FReadStr() and FSeek(). FReadStr() reads a specified number of bytes from a file up to the next null (Chr(0)) character. FSeek() moves the file pointer without reading. This function is assumed to handle raw binary data and is not dependent upon the status of SetAnsi(). FReadText() and FRead4(), on the other hand, are dependent upon SetAnsi().
Examples
This example uses FRead() after successfully opening a file to read 128 bytes into a buffer area:
X#
 1DEFINE F_BLOCK := 128
 2...
 3cBuffer := Space(F_BLOCK)
 4ptrHandle := FOpen2("temp.txt", FO_READ)
 5IF FError() != 0
 6    ? DOSErrString(FError())
 7ELSE
 8    IF FRead(ptrHandle, @cBuffer, F_BLOCK) <paramref name="" /> F_BLOCK
 9        ? DOSErrString(FError())
10    ENDIF
11    FClose(ptrHandle)
12ENDIF
See Also