Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FClose

FClose( [nHandle] ) --> lRet

Closes a file handle owned by the routine.

FCloseAdvPL
01 · OVERVIEW

Overview

FClose returns true on closure and false on failure; consult FError after failure for details. A file handle is not a table alias. The community example creates a file first; this adaptation opens an existing test file read-only, accepts handle zero and closes on the normal path. An absent file produces an open diagnostic without creating a replacement. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

FClose( [nHandle] ) --> lRet

Parameters

nHandle
NumericOptional

Valid handle to close, explicitly supplied in this example.

Return value

Logical closure success.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
#Include "Fileio.ch"

User Function Ed378()
    Local nHandle := FOpen("editorial-test.txt", FO_READ + FO_SHARED)
    // Handle zero is valid; do not require greater than zero.
    If nHandle >= 0
        If !FClose(nHandle)
            ConOut(cValToChar(FError()))
        EndIf
    Else
        ConOut(cValToChar(FError()))
    EndIf
Return Nil
Expected result

Closes after successful opening; failures report a code without file content. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check path, permissions, platform and handle ownership. Close only handles obtained by this routine, including complete-application error handling.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FClose. TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Arquivos de Disco/FClose.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha