Extends Xojo.Core.Date

  1. 2 weeks ago

    Etienne P

    Apr 13 Montreal, Canada
    Edited 2 weeks ago

    Simple code :

    Method Day
      Extends d as Xojo.Core.Date, pDay as integer
    
    dim nwD as New Xojo.Core.Date(d.Year, d.Month, pDay, d.Hour, d.Minute, d.Second, d.Nanosecond, d.TimeZone)
    d = nwD

    'd' has the new date, but when it returns into the calling method, i got the old date

    dim myDate as Xojo.Core.date = Xojo.Core.Date.Now
    myDate.day(4)

    // normaly change the day to 4 but still have the old date

    any idea ?

  2. Norman P

    Apr 13 Pre-Release Testers, Xojo Pro Enjoying Whistler BC
    Edited 2 weeks ago

    when you assign a new instance IN the method then it is swapped for the duration of that method only

    and when you exit that method the local is not retained

    you need to pass it in BYREF to change the referred to object and have it be retained when the method exits

    Method Day
      Extends byref d as Xojo.Core.Date, pDay as integer

    https://blog.xojo.com/2019/01/24/some-follow-up-regarding-byref/
    https://blog.xojo.com/2019/01/23/byref-vs-reference-types/
    https://blog.xojo.com/2018/12/12/what-kind-of-variable-are-you/

    That said I'm not sure this style is going to work in this case since the call is an expression and you cant pass expressions byref

  3. Etienne P

    Apr 13 Montreal, Canada

    look's it doesn't work :-(

    You can't pass an expression as a parameter that is defined as ByRef

    i will use a simple assign with a return value instead :-/

  4. Norman P

    Apr 13 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    @Etienne P look's it doesn't work :-(

    And why I said

    @Norman P That said I'm not sure this style is going to work in this case since the call is an expression and you cant pass expressions byref

  5. Etienne P

    Apr 13 Montreal, Canada

    sorry, i didnt saw your modifed post

or Sign Up to reply!