HEADER()

This forum is meant for questions about the Visual FoxPro Language support in X#.

User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

HEADER()

Post 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.
FFF
Posts: 1581
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

HEADER()

Post 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
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

HEADER()

Post by Chris »

Yes, Kevin most probably the compiler reports an error at a different line of your code, not on this assignment.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

HEADER()

Post 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
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

HEADER()

Post 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.
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

HEADER()

Post 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.
______________________
Johan Nel
Boshof, South Africa
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

HEADER()

Post 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.
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

HEADER()

Post 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
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

HEADER()

Post by Chris »

Thanks guys, both problems of course confirmed and logged. Should be both fixed in the next build.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

HEADER()

Post 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
Post Reply