Click or drag to resize

FClose Function

Close an open file and write the buffers to disk.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.5
Syntax
 FUNCTION FClose(
	ptrHandle AS IntPtr
) AS LOGIC

Parameters

ptrHandle
Type: IntPtr
The handle of the open file you want to close.

Return Value

Type: Boolean
FALSE if an error occurs while writing; otherwise, TRUE.
Remarks
FClose() is a low-level file function that closes files and forces the associated buffers to be written to disk.
If the operation fails, FClose() returns FALSE and FError() can be used to determine the specific error.
For example, attempting to use FClose() with an invalid handle returns FALSE and FError() returns error 6, invalid handle.
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 FClose() to close a newly created file and displays an error message if the close fails:
X#
1ptrHandle := FCreate("testfile", FC_NORMAL)
2IF !FClose(ptrHandle)
3    ? DOSErrString(FError())
4ENDIF
See Also