copy or reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Albert Krüger

    copy or reference

    Hello,

    when I return an object from a function, get I a copy or a reference to the
    calling function?

    function AnyFunction as MyClass
    dim objectOfMyClass as MyClass
    ....
    return objectOfMyClass
    end function

    objectOfCall = AnyFunction 'copy or reference?

    I think a copy, but I am not sure.

    Albert Krüger


  • Cor Ligthert

    #2
    Re: copy or reference

    Kruger,

    With "object" types forever a reference.

    Passing byval means passing the reference for those types. I assume that
    because of your question that can give as well a misunderstandin g for you.

    I hope this helps,

    Cor


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: copy or reference

      "Albert Krüger" <albert.krueger @mhp-net.de> schrieb:[color=blue]
      > when I return an object from a function, get I a copy or a reference to
      > the
      > calling function?
      >
      > function AnyFunction as MyClass
      > dim objectOfMyClass as MyClass
      > ...
      > return objectOfMyClass
      > end function
      >
      > objectOfCall = AnyFunction 'copy or reference?
      >
      > I think a copy, but I am not sure.[/color]

      If 'MyClass' is a reference type (class), the function will return a
      reference, otherwise (value type, structure) it will return a "copy".

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      Working...