Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: pber on June 23, 2014, 03:21:03 AM

Title: how to pass a string between instances
Post by: pber on June 23, 2014, 03:21:03 AM
...this causes a gpf to me
Am I wrong?

Code: [Select]
class provider
  s1 as string
  method getString() as string
    return s1
  end method
end class

class user
  s2 as string
  method setString(s as string)
    s2=s
  end method
end class

provider o1
o1.s1="123"

user o2

' just do this,
o2.s2 = o1.s1

' but using methods instead of directly accessing members
o2.setString(o1.getString()) ' XXX breaks
Title: Re: how to pass a string between instances
Post by: Charles Pegge on June 23, 2014, 05:22:57 AM
Hi Paolo,

If you pass the string byval, it will work. I will remedy this problem, which I suspect is between the function returning the string and the expectation of a string parameter to be passed byref.

class user
  s2 as string
  method setString(byval s as string)
    s2=s
  end method
end class

or simply:

class user
  s2 as string
  method setString(string s)
    s2=s
  end method
end class

Title: Re: how to pass a string between instances
Post by: pber on June 23, 2014, 05:36:04 AM
Hi Charles,

Does it mean that:
1) method m( id as type ) is implicitly myRef
2) method m( type id ) is implicitly byVal
?
Title: Re: how to pass a string between instances
Post by: Charles Pegge on June 23, 2014, 06:17:08 AM
Yes, byref is the default when using the old 'as' syntax
Title: Re: how to pass a string between instances
Post by: pber on June 23, 2014, 07:52:06 AM
...now it works  :-*
tnx