Hi Antonio,
i think your defines should be declared in this way
Code: Select all
* VFP standard flags
DEFINE S2F_FLAG_OVERWRITE = 0x0000
DEFINE S2F_FLAG_APPEND = 0x0001
DEFINE S2F_FLAG_UNICODE_LE = 0x0002
DEFINE S2F_FLAG_UTF8 = 0x0004
* X# extension flags
DEFINE S2F_FLAG_UNICODE_BE = 0x0008
DEFINE S2F_FLAG_UNICODE_FORMATS = (S2F_FLAG_UNICODE_LE | S2F_FLAG_UTF8 | S2F_FLAG_UNICODE_BE)
DEFINE S2F_FLAG_UNICODE_TEXT = 0x0100
I can´t comment in which situation VFP throws an runtime error or surpresses the error and sets maybe an VFP internal errorcode instead ? , but when i look at the places where you currently want to throw an error you should change that to:
Code: Select all
THROW ArgumentException { String.Format("Param value {0} is invalid" , Flags ) , NAMEOF ( Flags ) }
and
Code: Select all
TRY
File.AppendAllText(Filename, Expression, UnicodeEncoding)
CATCH e AS Exception
THROW e
ENDTRY
X# File functions like Fcreate() don´t throw an runtime error. If such a func fails the dos errorcode and the *
exception* is stored in the RuntimeState object. When i run this code your function returns 0, but i´m able to see why Fcreate() failed:
Code: Select all
? StrToFile ( "Drive 'P' doesn´t exist !" , "P:test.txt" , S2F_FLAG_UTF8 )
IF RuntimeState.FileError > 0
? RuntimeState.FileError , DosErrString ( RuntimeState.FileError )
?
IF RuntimeState.FileException != NULL
THROW RuntimeState.FileException
ENDIF
ENDIF
i see the errorcode 3, the errorcode description and the exception. This exception could also be thrown within your StrToFile() function e.g.
Code: Select all
...
FHandle = FCreate(Filename)
IF FHandle != F_ERROR
IF ! (BOM == "")
Result = FWrite(FHandle, BOM)
ENDIF
Result += FWrite(FHandle, Expression)
FClose(FHandle)
ENDIF
IF RuntimeState.FileError > 0 .AND. RuntimeState.FileException != NULL
THROW RuntimeState.FileException
ENDIF
...
All depends on what your VFP does if an invalid param is used or a file operation fails.
P.S. Forgot to mention FError(). This function returns the current RuntimeState.FileError value.
regards
Karl-Heinz