Page 1 of 1
VO code translation to X#
Posted: Fri Oct 18, 2019 12:22 pm
by wriedmann
Hello,
I have such code in my Visual Objects code library:
Code: Select all
local nCast as dword
local dDate as Date
dDate := Today()
nCast := dword( _cast, dDatum )
I don't like that code, but how can I translate it to a more correct form?
Strange enough that calling it in X# code it returns the same values as in VO....
Thank you very much!
Wolfgang
VO code translation to X#
Posted: Fri Oct 18, 2019 12:27 pm
by robert
Wolfgang,
what do you want to do with nCast ?
And why is it strange that we are returning the same numeric value ?
We are returning the Julian date number with the same algorithm that VO uses:
https://github.com/X-Sharp/XSharpPublic ... e.prg#L291
Robert
VO code translation to X#
Posted: Fri Oct 18, 2019 12:31 pm
by wriedmann
Hi Robert,
thank you very much!
And why is it strange that we are returning the same numeric value ?
Casts, specially from non-numeric values to numeric one are really a bad thing, full of side effects, when it comes to 32/64 bit code, so I try to remove them whenever possible.
Wolfgang
VO code translation to X#
Posted: Fri Oct 18, 2019 1:36 pm
by wriedmann
Hi Robert,
sorry, this is the entire VO code:
Code: Select all
function Week( dDate as date ) as int pascal
local nJ as dword
local nD4 as dword
local nL as dword
local nD1 as dword
local nDiff as int
nJ := dword( _cast, dDate )
nD4 := ( ( ( nJ + 31741 - ( nJ % 7 ) ) % 146097 ) % 36524 ) % 1461
nL := Integer( nD4 / 1460 )
nD1 := ( ( nD4 - nL ) % 365 ) + nL
nDiff := Integer( nD1 / 7 ) + 1
return nDiff
and this the X# version (not using the X# runtime, but compatible to my VO code):
Code: Select all
static method Week( self dDatum as DateTime ) as int
local nJ as int
local nD4 as int
local nL as int
local nD1 as int
local nDiff as int
nJ := ( dDatum:Date - DateTime{ 1901, 1, 1 } ):Days + 2415386
nD4 := ( ( ( nJ + 31741 - ( nJ % 7 ) ) % 146097 ) % 36524 ) % 1461
nL := nD4 / 1460
nD1 := ( ( nD4 - nL ) % 365 ) + nL
nDiff := ( nD1 / 7 ) + 1
return nDiff
Thank you again!
Wolfgang
VO code translation to X#
Posted: Fri Oct 18, 2019 2:32 pm
by robert
Wolgang,
In this case both DWORD(_CAST, dDate) and (DWORD) dDate will call the same code and are quite harmless.
Robert
VO code translation to X#
Posted: Fri Oct 18, 2019 2:34 pm
by wriedmann
Hi Robert,
thank you very much!
Wolfgang