xsharp.eu • HEADER()
Page 1 of 2

HEADER()

Posted: Tue Feb 25, 2020 9:56 pm
by kevclark64
It seems like this should work fine:

Code: Select all

local iHeaderVal as Int
iHeaderVal=Header()
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.

HEADER()

Posted: Tue Feb 25, 2020 10:12 pm
by FFF
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

HEADER()

Posted: Wed Feb 26, 2020 8:05 am
by Chris
Yes, Kevin most probably the compiler reports an error at a different line of your code, not on this assignment.

HEADER()

Posted: Wed Feb 26, 2020 8:50 am
by Karl-Heinz
Hi Chris,

The Header() sources are:

Code: Select all

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 ?

Code: Select all

    oDtaDlg := DtaDlg { SELF }
 
    ? small->Alias()   // ok, "small"
   ? Alias()   // ok, "small" 
   
   ? oDtaDlg:server:header    // ok, 322
   
//   ? small->Header()  // still a invalid cast exception
//   ? Header()  // still a invalid cast exception 
    
	oDtaDlg:Show()
regards
Karl-Heinz

HEADER()

Posted: Wed Feb 26, 2020 1:49 pm
by kevclark64
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.

HEADER()

Posted: Wed Feb 26, 2020 2:01 pm
by lumberjack
Hi Kevin,
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.

HEADER()

Posted: Wed Feb 26, 2020 2:39 pm
by kevclark64
Changing to LONG still gives the same error. In fact even doing this gives the same error:

? header()

That makes me think the error is internal to the function rather than an error in assigning the result to a variable.

HEADER()

Posted: Wed Feb 26, 2020 3:04 pm
by Karl-Heinz
Hi Kevin,

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.

Code: Select all

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


regards
Karl-Heinz

HEADER()

Posted: Fri Feb 28, 2020 7:35 pm
by Chris
Thanks guys, both problems of course confirmed and logged. Should be both fixed in the next build.

HEADER()

Posted: Sat Feb 29, 2020 6:24 am
by Karl-Heinz
Hi Chris,

i forgot to mention it here - i already logged it two days ago.

https://github.com/X-Sharp/XSharpPublic/issues/335

regards
Karl-Heinz