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

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

Post Reply
Anonymous

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

Post 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 202 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

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

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

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

Post 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply