xsharp.eu • How to wrap X# ValType() function to use for VFP VarType() function???
Page 1 of 1

How to wrap X# ValType() function to use for VFP VarType() function???

Posted: Mon Apr 27, 2020 3:33 pm
by Anonymous
How can I use the #command syntax to make VFP VarType() function calls to use the X# ValType() function?

Here is what I tried, but I get rrun-time errors when my code calls VarType()
.

Code: Select all

#command VarType(<*uValue*>) => ValType(<(uValue)>)
Is also tried this:

Code: Select all

#command VarType(<*uValue*>) => ValType(<uValue>)
2020-04-27 10_28_01-Window.png
2020-04-27 10_28_01-Window.png (14.79 KiB) Viewed 424 times
If I write my own Function for VarType() top call ValType() it works fine, but I'd rather do it with the pre-compiler.
.

Code: Select all

Function VarType(uValue)
	
    Return ValType(uValue)
  
End Function

How to wrap X# ValType() function to use for VFP VarType() function???

Posted: Mon Apr 27, 2020 3:42 pm
by robert
Matt,

#command is meant for translations that span a whole statement.
In this case you need #translate of #xtranslate, because VarType() will be in the middle of another line of code.
I would recommend #xtranslate because otherwise also abbreviations will be matched.

Robert

How to wrap X# ValType() function to use for VFP VarType() function???

Posted: Mon Apr 27, 2020 3:51 pm
by FoxProMatt
Thanks Robert!

This does it:

Code: Select all

#xtranslate VarType(<uValue>) => ValType(<uValue>)

Can you put this into one of the next releases? Would it go into FoxProCmd.xh file?

How to wrap X# ValType() function to use for VFP VarType() function???

Posted: Tue Apr 28, 2020 7:35 pm
by Karl-Heinz
Guys,

a question about the data types DateTime and Currency.

Both data types can be used with FP and VO. What i don´t understand are the differences i see when i toggle the dialect and check the types within a "as usual" function:

Code: Select all

FUNCTION TestDateTimeAndCurrency() AS VOID
LOCAL dt AS DateTime
LOCAL c AS Currency
 
dt := DateTime(2000,12,2)
c := 12.45

// ok, the FP and VO dialect show the same results
? dt  // 02.12.2020 00:00:00
? c   // 12,4500
?
// ok, the FP and VO dialect show the same results
dt:GetType():ToString()  // System.DateTime
c:GetType():ToString()   // XSharp.__Currency 
?
? "Test DateTime:"
TestUsual ( dt )
?
? "Test Currency:" 
TestUsual ( c ) 
?

RETURN 

           
FUNCTION TestUsual ( u AS USUAL ) AS VOID 

/*	
 The VO dialect shows: 

	XSharp.__Usual
	XSharp.__Usual 
	
  while the FP dialect shows:
  
	System.DateTime
 	XSharp.__Currency

*/

? u:GetType():ToString()   

RETURN 
i hope you can follow me ;-)

btw. according the FP docs: VarType ( <DateTime> ) returns "T" and varType ( <Currency> ) "Y"

regards
Karl-Heinz

How to wrap X# ValType() function to use for VFP VarType() function???

Posted: Wed Apr 29, 2020 12:03 pm
by robert
Karl-Heinz ,

- ValType() has been fixed.
- The other difference is caused by the fact that in the VO dialect u:GetType() is early bound and in FoxPro late bound. And apparently the early bound code returns the GetType() of the usual itself and the late bound code returns the GetType() of the contents of the usual.
If you change the code to:

Code: Select all

? ((OBJECT)u):GetType():ToString()

Then in both dialects you will get the type of the contents of the usual.
This is one of those 'Edge cases'. I am not sure what the right behavior should be here...

Robert