FUNCTION FReadLine( ptrHandle AS IntPtr, nMax AS DWORD ) AS STRING
public static string FReadLine( IntPtr ptrHandle, uint nMax )
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()
ptrHandle := FOpen2("docs.txt", FO_READ) IF ptrHandle != F_ERROR DO WHILE !FEOF(ptrHandle) ? FReadLine(ptrHandle) ENDDO ENDIF FClose(ptrHandle)
FUNCTION Grep(cSearch, cFile AS STRING) ; AS DWORD PASCAL LOCAL handle AS PTR LOCAL Count AS DWORD LOCAL Line AS STRING Line := " " handle := FOpen2(file, FO_READ) cSearch := Upper(cSearch) DO WHILE !FEOF(handle) line := Upper(FReadLine(handle)) IF InStr(cSearch, line) ? line Count += 1 ENDIF ENDDO RETURN Count