Author Topic: how to pass a string between instances  (Read 1300 times)

0 Members and 1 Guest are viewing this topic.

paolo

  • Jr. Member
  • **
  • Posts: 70
how to pass a string between instances
« 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

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3584
    • Oxygen Basic
Re: how to pass a string between instances
« Reply #1 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



paolo

  • Jr. Member
  • **
  • Posts: 70
Re: how to pass a string between instances
« Reply #2 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
?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3584
    • Oxygen Basic
Re: how to pass a string between instances
« Reply #3 on: June 23, 2014, 06:17:08 AM »
Yes, byref is the default when using the old 'as' syntax

paolo

  • Jr. Member
  • **
  • Posts: 70
Re: how to pass a string between instances
« Reply #4 on: June 23, 2014, 07:52:06 AM »
...now it works  :-*
tnx