but the 2nd line gives an error saying "Specified cast is not valid." I've tried declaring iHeaderVal as int16, int32, int64, usual, and not declaring it at all. They all give the same error.
Kevin,
made a new x#-runtime app from xides gallery, changed dialect to x#/Foxpro and added your two lines:
FUNCTION Start( ) AS VOID
LOCAL uXSharpUsual AS USUAL
uXSharpUsual := "Hello X# runtime!"
System.Console.WriteLine(AsString(uXSharpUsual))
LOCAL iHeaderVal AS INT
iHeaderVal=Header()
RETURN
compiles here using 2.3 (not "a", yet) - only gives warning for unused iHeaderVal
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
FUNCTION Header() AS LONG
LOCAL oValue := NULL AS OBJECT
VoDb.Info(DBI_GETHEADERSIZE, REF oValue)
RETURN (LONG) oValue
There is no check on what Info() returns, so instead of returning 0 a invalid cast exception is thrown if Info () fails. * But * the exception is also thrown when a workarea is in use ?
To check this again, I created a new Windows Forms Application, added the XSharp references, switched the dialect to Foxpro, added a button, and in the Click event put these lines:
USE "e:fpd26blp3" IN 1
local iHeaderVal as Int
iHeaderVal=Header()
that still gives the "invalid cast" error. BTW, this a runtime error, not a compile error. Sorry that was unclear before.
Kevin Clark wrote:To check this again, I created a new Windows Forms Application, added the XSharp references, switched the dialect to Foxpro, added a button, and in the Click event put these lines:
USE "e:fpd26blp3" IN 1
local iHeaderVal as Int
iHeaderVal=Header()
that still gives the "invalid cast" error. BTW, this a runtime error, not a compile error.
Although it is not really an error except if Header() returns a value greater than MaxInt, if you change your iHeaderVal type to LONG. Technically speaking INT, LONG, LONGINT are all mappings to Int32. Think it is just a small glitch that could easily be fixed.
______________________
Johan Nel
Boshof, South Africa
In addition to my previous post: There´s a problem with the current Header() function. If there´s no workarea open Header() must return 0, otherwise the size of the Header. Try this.
FUNCTION TestHeader() AS VOID
LOCAL iHeaderVal AS INT
// iHeaderVal=Header() // throws a null reference exception
iHeaderVal=XHeader() // 0 , ok
USE "e:fpd26blp3" IN 1
// iHeaderVal=Header() // throws a invalid cast exception
iHeaderVal=XHeader() // your Dbf header size is shown
RETURN
FUNCTION XHeader() AS LONG
LOCAL oValue AS USUAL
VoDb.Info(DBI_GETHEADERSIZE, REF oValue)
RETURN (LONG) oValue