nHandleValid handle from FOpen/FCreate; zero is valid too.
AdvPL GuideFReadStr( nHandle, nQtdBytes ) --> cRetReads up to a byte limit and returns text.
FReadStr returns a string unlike FRead’s numeric count. It can stop at Chr(0), EOF or error; it is not a generic replacement for binary content requiring preserved null bytes. The GitHub source demonstrates reading through a writable open mode; this adaptation uses read-only access and captures diagnostics before closure. Returned length depends on file and position rather than Unicode character count. (TOTVS, n.d., ref. 1)
FReadStr( nHandle, nQtdBytes ) --> cRetnHandleValid handle from FOpen/FCreate; zero is valid too.
nQtdBytesRequested byte limit.
Text read up to the limit, null or EOF.
#Include "Protheus.ch"
#Include "Fileio.ch"
User Function Ed394()
Local nHandle := -1
Local nError := 0
Local cText
// 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
cText := FReadStr(nHandle, 64)
nError := FError()
// Report size without exposing file content.
ConOut(cValToChar(Len(cText)))
If nError <> 0
ConOut(cValToChar(nError))
EndIf
If !FClose(nHandle)
ConOut(cValToChar(FError()))
EndIf
EndIf
Return NilLength up to 64 bytes or a diagnostic; content is not shown. 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.