date variable value changes unexpected

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

date variable value changes unexpected

Postby tgs » Fri Aug 22, 2014 12:19 pm

In my function I have date variables (_date1, _date2) to set different payment dates by given terms (_pay1, _pay2).
The function is working so var so good, but when the first payment date (_date11) get its value the date variable (_date2) is changing to the value of _date11???
date4.png
date4.png (119.42 KiB) Viewed 3481 times


date3.png
date3.png (152.26 KiB) Viewed 3481 times

At the next step the value of _date2 changes to the value of _date1:
date2.png
date2.png (152.67 KiB) Viewed 3481 times

And when I execute the next step the values of _date1 and _date2 are the 'Sat Mar 02 00:00:00 CET 2013'!?

The main problem for me is that the value of _date21 is always wrong.
I cannot understand how the variables (_date1 + _date2) can change their value?

Servoy 7.4.1
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: date variable value changes unexpected

Postby boonstrj » Fri Aug 22, 2014 12:34 pm

Be aware that date variables are objects. Thus if you call that functions with the same variable date for _date1 and _date2 means if you change _date1 than also _date2 changes because it's the same object.
Jeroen Boonstra
2Serve-IT

Servoy version 5.2.13/6.1.x/7.1.0
boonstrj
 
Posts: 63
Joined: Mon Jan 07, 2008 11:49 am
Location: Netherlands

Re: date variable value changes unexpected

Postby tgs » Fri Aug 22, 2014 1:11 pm

But _date1 and _date2 are two seperate parameter of the function!? They are two different variables, or?
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: date variable value changes unexpected

Postby ROCLASI » Fri Aug 22, 2014 1:30 pm

Hi Thomas,

Dates are always passed as a reference to other functions.
Are doing perhaps doing something like this?
Code: Select all
var _dDate = new Date();
myOtherMethod(_dDate, _dDate);


function myOtherMethod(_dDate1, _dDate2) {
    // both params point to the same original date object
}

if so you should create a new date object using the other like so:
Code: Select all
var _dDate = new Date();
myOtherMethod(_dDate, new Date(_dDate));


function myOtherMethod(_dDate1, _dDate2) {
    //now you have unique date objects
}
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: date variable value changes unexpected

Postby tgs » Fri Aug 22, 2014 2:16 pm

Thank you Robert!
You are right and I changed my code like your example. Now it works as expected.
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 6 guests