nHandleValid handle from FOpen/FCreate; zero is valid too.
AdvPL GuideFRead( nHandle, @cBufferVar, nQtdBytes ) --> nRetReads bytes into a buffer and returns the count.
FRead returns a number; data arrives in a preallocated buffer passed by reference. Do not replace that buffer with the returned count. Both old official and community examples contain sections not fully respecting this preparation: the adaptation uses Space(64), @cBuffer and a separate nRead. A short read can indicate EOF or error; capture FError before closing. The fragment prints no file content and assumes no guaranteed 64 bytes. (TOTVS, n.d., ref. 1)
FRead( nHandle, @cBufferVar, nQtdBytes ) --> nRetnHandleValid handle from FOpen/FCreate; zero is valid too.
cBufferVarBuffer sized >= nQtdBytes, by reference.
nQtdBytesMaximum requested in this read.
Number of bytes actually read.
#Include "Protheus.ch"
#Include "Fileio.ch"
User Function Ed393()
Local nHandle := -1
Local nError := 0
Local cBuffer := Space(64)
Local nRead
// Pre-existing fictional file in the test context; shared reading.
nHandle := FOpen("editorial-test.txt", FO_READ + FO_SHARED)
If nHandle < 0
nError := FError()
ConOut(cValToChar(nError))
Else
// Buffer and requested size differ from the numeric return.
nRead := FRead(nHandle, @cBuffer, 64)
nError := FError()
ConOut(cValToChar(nRead))
If nError <> 0
ConOut(cValToChar(nError))
EndIf
If !FClose(nHandle)
ConOut(cValToChar(FError()))
EndIf
EndIf
Return NilCount up to 64 bytes or a diagnostic; this is one read rather than a complete reader. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.