date literals in Foxpro

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

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

date literals in Foxpro

Post by Karl-Heinz »

robert wrote:Thomas,
I think we can manage to add these function for the FoxPro language without having to use preprocessor tricks.
because you mentioned the preprocessor, i gave it a try - and it works :-).

Code: Select all

#TRANSLATE Date ( <year> , <month> , <day> ) => @@Date( <year>, <month>,<day> ) 
#TRANSLATE Date ( ) => @@Date()

FUNCTION @@DATE(tnYear AS INT, tnMonth AS INT, tnday AS INT) AS DATE 
RETURN ConDate ( (DWORD) tnYear , (DWORD) tnMonth , (DWORD) tnday  )   
	
FUNCTION @@DATE() AS DATE 
RETURN Today()


FUNCTION Start() AS VOID

? Date()

? Date ( 2000 , 12 , 1 )

RETURN 

It seems that the escape chars in the Function declarations are not really needed, because it also works without these chars.

FUNCTION DATE(tnYear AS INT, tnMonth AS INT, tnday AS INT) AS DATE
RETURN ConDate ( (DWORD) tnYear , (DWORD) tnMonth , (DWORD) tnday )

FUNCTION DATE() AS DATE
RETURN Today()

The abilities of the preprocessor are impressive !

regards
Karl-Heinz
User avatar
robert
Posts: 4262
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

date literals in Foxpro

Post by robert »

Karl-Heinz ,

Thanks. So maybe we will not have to add this to the compiler but can handle it in the header file.
Btw why are you declaring the arguments as int and then casting them to a dword ? Why not simply declare them as DWORD.
And did you consider to write the UDCs as:

Code: Select all

#TRANSLATE Date ( <year> , <month> , <day> ) => ConDate( <year>, <month>,<day> ) 
#TRANSLATE Date ( ) => Today()

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

date literals in Foxpro

Post by Karl-Heinz »

Hi Robert,

i simply used the INT sample that Thomas posted. The main goal was to see if and how the escape chars are handled.

#TRANSLATE Date ( <year> , <month> , <day> ) => ConDate( <year>, <month>,<day> )
#TRANSLATE Date ( ) => Today()

yeah, didn´t investigate further, because i thought you don´t want the preprocessor to do the job.

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

date literals in Foxpro

Post by Karl-Heinz »

Hi Robert,

How is your decision to implement the Date() and DateTime() functions ? After some attempts with the preprocessor, it seems that this is the only possibility to evaluate a preprocessed Date() function ?

Code: Select all


#XTRANSLATE DATE() => @@DATE()
#XTRANSLATE DATE ( <year> , <month> , <day> ) 	=> @@Date ( <year>, <month>,<day> ) 


FUNCTION DATE() AS DATE
	
	RETURN Today()


FUNCTION DATE( year AS DWORD , month AS DWORD  , day AS DWORD ) AS DATE
	
	RETURN ConDate ( year , month , day  )


FUNCTION Start() AS VOID

?   Evaluate ( "@@Date()+ 1" )   // doesn´t work without the escape sequence
?   Evaluate ( "@@Date( 2011 , 12 , 7 ) + 1" )   // doesn´t work without the escape sequence

?   Eval ( MCompile ( "@@Date()+ 1"   ) )   // doesn´t work without the escape sequence
?   Eval ( MCompile ( "@@Date( 2011 , 12 , 7 ) + 1" ) )   // doesn´t work without the escape sequence

?   Eval ( {|| Date()+ 1 } )
?   Eval ( {|| Date( 2011 , 12 , 7 ) + 1} )

?   Eval ( {|n| DATE()+ n } , 12  )
?   Eval ( {|n| DATE( 2011 , 12 , 7 ) + n} , 12  )


RETURN

regards
Karl-Heinz
Post Reply