Simple code :
[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[/code]
‘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 ?
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
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 :-/
look’s it doesn’t work
And why I said
[quote=432602:@Norman Palardy]
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[/quote]
sorry, i didnt saw your modifed post