2 Replies - 314 Views - Last Post: 12 December 2012 - 11:07 AM Rate Topic: -----

#1 depricated  Icon User is offline

  • You and me had such wonderful times when I'm all by myself.

Reputation: 879
  • View blog
  • Posts: 2,867
  • Joined: 13-September 08

Storing Objects ByRef

Posted 12 December 2012 - 09:29 AM

So this is going back to the concept of Pointers in C++.

Basically, what I want to do is instantiate an Object in one class, pass it to another ByRef (which should work like a pointer, right?) and then store the reference in a local variable so I can use it in the class.

i.e.

Public Class Process
    Private _db As AccessFacade

    Public Sub SetDB(ByRef db As AccessFacade)
        _db = db
    End Sub
End Class

Public Class Main
    Private Sub OpenProcess()
        Dim process As New Process
        process.SetDB(_db)
    End Sub
End Class
I mean, assuming that Class Main has a private _db that is an AccessFacade, etc.

Basically I have a class that's going to act as a gateway between the application and the database. Since it's a DB driven application, it will see lots of use. Rather than instantiating it every time I want to run a query, or on every form, I'd like to just start it when the application starts and keep it alive.

Is there a more appropriate way to do this that I might be missing?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Storing Objects ByRef

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: Storing Objects ByRef

Posted 12 December 2012 - 10:07 AM

Objects are reference types anyway. You don't have to do anything special with them. Any use of them is really through a reference to them. So you can just pass the variable that is the instance of the object you're working with.

List of types that are reference types:
http://msdn.microsof...y/490f96s2.aspx
Was This Post Helpful? 1
  • +
  • -

#3 depricated  Icon User is offline

  • You and me had such wonderful times when I'm all by myself.

Reputation: 879
  • View blog
  • Posts: 2,867
  • Joined: 13-September 08

Re: Storing Objects ByRef

Posted 12 December 2012 - 11:07 AM

Awesome! Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1