Page 2 of 2
date literals in Foxpro
Posted: Sat Nov 09, 2019 10:23 am
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
date literals in Foxpro
Posted: Sat Nov 09, 2019 12:06 pm
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
date literals in Foxpro
Posted: Sat Nov 09, 2019 1:22 pm
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
date literals in Foxpro
Posted: Sat Nov 16, 2019 1:33 pm
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