CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Dec 2007
    Posts
    234

    Re: Modify Object by reference

    mmmmmmm..... I think some thing was over looked here....
    There is a difference in class fields, vs class properties...

    Class fields:
    Code:
    Public Class Test
      Public SomeName as String
      Public Age as Integer
    End Class
    Are treated as value types....

    While a property:
    Code:
    Public Class Test
      Public Property SomeName as String
      Public Property Age as Integer
    End Class
    (yes, I realized I use the VB10 syntax there, sue me, point still applies)
    Get treated as reference types and are part of the object.

    The difference in this distinction causes the rules to change when they are passed around. And has a lot to do with where they get stored (heap vs stack).

    Gremlins - I don't buy that (at least no with out references (no pun intended)) ... granted it's been sometime since i've been out of th VB6 game... but if memory serves (and it could be faulty, I will grant that) ... that's NOT the experience I remember and I did a LOT of work with system that was heavy on the DLLs.

    WOF - you SHOULD be able to pass an object's property by ref to be modified... but it has to be a PROPERTY... not a field... they are not interchangeable... in your first post, you show them as fields... not properties.

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  2. #17
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Modify Object by reference

    Quote Originally Posted by TechGnome View Post
    you SHOULD be able to pass an object's property by ref to be modified... but it has to be a PROPERTY... not a field... they are not interchangeable... in your first post, you show them as fields... not properties.

    -tg
    Do you have VB6 installed ???

    Try it...

    It will not change a byref property, no matter how you try...

    I'll look for a few online references, problem is that anything VB6 is not so easy to find anymore...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #18
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Modify Object by reference

    Right, Gremlin. A property canNOT be modified byref, neither if it was declared a public field, nor a property get/let pair.
    Alas, a thing like "Public Property Somename as String" does not exist in VB6, TechGnome.

    I mean, I would have expected that a property, being actually a pair of routines to receive or give back a value, cannot be modified byref, being no actual memory location.
    But a public field should be, or so I had expected.

    I think this is because of the policy, or better: the way how value passing in VB6 objects is done at all. If you have a get/let pair, it is obvious that there is no actual memory location for that property, because it might even be assembled or computed within the get routine. So the result is stored somewhere in a temporary field. That is like a ByVal parameter passed to a function.
    So I think the interface is always doing this. It creates a temporary field where it puts the result of the property-get. In case there is only a public variable it results in putting the contents of this var into the accessible temp field. The user will find n0 difference in using the resulting value, but it NEVER ever allows byref modification.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured