I have 3 relevant variables: a property of array of String local to the method (aTemp()); a Date property local to the method (tstDte); a public Date property to a Window (CmpBDate).
I use these properties to verify certain info. I unfortunately put a “0” in an array with the 0 in a date location for the string and it wasn’t easy getting it out.
I use tstDte to tell if it’s a good or bad date that is in aTemp(12) or another piece like file’s creation date.
The one line of code I ran into a problem is:
tstDte.SQLDateTime = aTemp(12)
Even though CmpBDate is not mentioned it immediately changes at this line.
That is corruption of a variable.
I also know it was that line because I added a Date variable for just that spot and the corruption didnt happen.
Why???
I do. I forgot to add I use tstDte in comparison with CmpBDate and assign it under certain conditions. It is here only that it corrupts. They do point mutually at times to each other but not here
Date objects are POINTERS… so as Roger said, if two date “variables” point to the same object, change one, changes the other
Dim Date1 as New Date
Dim Date2 as New Date
// at this point both are independent objects
Date2.totalSeconds = 100 // this changes the value of Date2, and Date1 does NOT change
//
Date1=Date2 // HOWEVER... at this point, the previous Date1 object is destroyed, and both Date1 and Date2 POINT at the same object
Date1.totalSeconds=5000 // since Date1 and Date2 point to the same place. Date2 just changed as well
but if you did THIS instead
Dim Date1 as New Date
Dim Date2 as New Date
// at this point both are independent objects
Date2.totalSeconds = 100 // this changes the value of Date2, and Date1 does NOT change
//
Date1.TotalSeconds=Date2 .TotalSecondsobject // this changes the VALUE of the Date1 object, NOT the pointer
//
Date1.totalSeconds=5000 // Date1 changes, and Date2 remains unchanged
This applies to ANY class object, those built into Xojo and those you create youself…
I usually add a CLONE method to overcome this “issue” (issue as it is in fact “by-design”)
Just to be clear, it’s not corruption, it’s incorrect code.
As Dave pointed out, if you need to compare 2 separate date objects
Date2.totalSeconds <> Date1.totalSeconds is one way