On Dec 11, 2006, at 7:36 PM, Michael wrote:

I found a solution, but really do not quite understand why.

With help from an earlier question, i have the following setup.


App.property as date (called kDate)

A method called getdate() returns to the caller a date like this.

  if kDate = nil then
    kDate =new date
  end if

  Return kDate


A class with a date also as a property, whose instances call the app with getdate().


This worked fine. But, I also needed to include a date verification method, which I implemented , in App, as:

ParseTheDate(s as string) as boolean.

  if ParseDate(s,kDate) then
  return true


If i looked at App. in the debugger, kDate showed the new date, but the properties in the classes did not change.


So, after stripping down the app, this does work.

  dim lDate As date
  if ParseDate(s,lDate) then
    kDate.TotalSeconds=lDate.TotalSeconds
    return true
  end if



Does this make sense? And the kDate the does show change with the first method, is this perhaps a "local" kDate?

You've been bitten by ParseDate's unfortunate interface. The Date parameter of ParseDate is passed by reference. If it succeeds, it replaces the Date object you passed in with an entirely new Date object. So kDate is not changed by ParseDate.

Also note that ParseDate parses dates, not dates + times. So if you need to compare dates only, comparing TotalSeconds may not work. For this I use the following function.

Function Equals(extends d1 as Date, d2 as Date) as Boolean
  if d2 <> nil then
    const SecondsInOneDay = 86400.0
return (Floor(d1.TotalSeconds/SecondsInOneDay) = Floor (d2.TotalSeconds/SecondsInOneDay))
  else
    return false
  end if
End Function


Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to