bArrayServer and long data type

This forum is meant for questions and discussions about the X# language and tools
Post Reply
boonnam
Posts: 88
Joined: Mon May 08, 2017 6:42 pm
Location: USA

bArrayServer and long data type

Post by boonnam »

I have a weird issue. I hope I can explain it clearly. We have a bArrayServer and its struct is like this:

Code: Select all

{{"MSEQ" 	,"N",2,0},;
{"MAGENT"	,"C",dwAgtNoFieldLen,0},;
{"MAGTPCT"	,"N",5,1},;
{"MAGTLVL"	,"C",dwAgtLvlFieldLen,0},;
{"MAGTOR"	,"C",2,0},;
{"MHCOMMIP" ,"L",1,0}}
We also have a bBrowser that is also using this bArrayServer structure. In one of of the method, we have something like this:

Code: Select all

LOCAL oAgentServer	AS bArrayServer

oAgentServer  := SELF:Owner:oDCBB_EditAgent:Server
After this line run, I can see the DBStruct of oAgentServer. The one I'm interested in is MAGTPCT. In the debugger I see that MAGTPCT data type is a long. Is this correct? This field is defined with one decimal ("N",5,1). Shouldn't it be a float?

Here come the weird part. In the same method, we have an array (LOCAL aAgents AS ARRAY) that contains the data that we need for oAgentServer. In the debugger, I can see the data of aAgents array. In this instance there are three agents. Each agent percent is 100.0 in aAgents array. To populate oAgentServer we have this loop:

Code: Select all

FOR i := j UPTO ALen(aAgents)
	oAgentServer:Append()
	oAgentServer:FIELDPUT( #MSEQ,		SELF:siSeq )
	oAgentServer:FIELDPUT( #MAGENT,		aAgents[i, kAGENT] )
	oAgentServer:FIELDPUT( #MAGTPCT,	aAgents[i, kAGENT_PCT] ) //<---My main focus
	oAgentServer:FIELDPUT( #MAGTLVL,	aAgents[i, kAGENT_LVL] )
	oAgentServer:FIELDPUT( #MAGTOR,		aAgents[i, kAGENT_OR] )
	oAgentServer:FIELDPUT( #MHCOMMIP,	aAgents[i, kAGENT_IP] )
	SELF:siSeq++
NEXT i
After this FOR NEXT loop, MAGTPCT should all be 100.0 as it is in aAgents. Running these codes in XSharp, only the first agent MAGTPCT is 100.0. The other two agent's MAGTPCT is 0. If I cast to long, it works:

Code: Select all

oAgentServer:FIELDPUT( #MAGTPCT,	(long)aAgents[i, kAGENT_PCT] )
Now all three agents MAGTPCT values are 100.0. I tried to cast to float. It doesn't work. Result in 0 for MAGTPCT for the last two agents. It crashed if I tried to cast to decimal. The error is "Specified cast is not valid".

Is this something we should be mindful of when assigning value to bArrayServer element? I found it odd that a field that is defined as "N", 5,1 as a long. Or is this a bug in XSharp that can be fixed? Thanks.

Boonnam
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

bArrayServer and long data type

Post by Chris »

Hi Boonam,

Please create and send us a repro sample for this. Just create a new small project, add some code to create and initialize a bArrayServer with the same data as in your real app, also add the same FOR loop code, make sure you still get the same results and post it so we can have a look.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
boonnam
Posts: 88
Joined: Mon May 08, 2017 6:42 pm
Location: USA

bArrayServer and long data type

Post by boonnam »

This is resolved by setting 'Use FLOAT literals' to true.
Post Reply