Announcement

Collapse
No announcement yet.

Pointers to objects?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointers to objects?

    OK, I'm just doing some preliminary stuff in learning OOP stuff, so bear with me.

    If I have an array of Objects, one of which is 'active' at a time.

    Can I create a pointer to the active object? i.e.

    Code:
    (Sort of)
    GLOBAL Tabs()    AS iTabData                       ' Table of active tab objects
    DIM ActiveTab    AS CLASS POINTER              ' (doesn't compile)
    ActiveTab = VARPTR?/CODEPTR?(Tabs(x))       ' Assign pointer
    What is the best method (efficiency and coding ease) to reference the active object's methods etc. from the active entry?

    Or am I Waaayyyy out in left field?

    George

  • #2
    ???

    Tabs(x).<method name>
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Local x as ... (interface name)

      x = nothing ' make sure an existing reference is released.

      Poke dword VarPtr( x ), ObjPtr(currentobject)
      x.addref()

      x.dosomething()

      release:
      x = nothing or just let it go out of scope (exit function).
      hellobasic

      Comment


      • #4
        Originally posted by Edwin Knoppert View Post
        Local x as ... (interface name)
        x = nothing ' make sure an existing reference is released.
        Poke dword VarPtr( x ), ObjPtr(currentobject)
        x.addref()
        x.dosomething()
        release:
        x = nothing or just let it go out of scope (exit function).
        I'm sorry, but that's not a good idea. Not good at all. It attempts to circumvent everything the compiler does for you automatically to protect you and prevent leaks. The following code accomplishes the same thing with complete safety and accountability:

        x = currentobject
        x.dosomething()


        Best regards,

        Bob Zale

        Comment


        • #5
          What was i thinking?
          hellobasic

          Comment


          • #6
            Thanks guys.

            Bob: OK, yours is straightforward, but what is 'x' defined as?

            George
            (OOP is clear in concept, murky in the details)

            Comment


            • #7
              Originally posted by George Deluca View Post
              Thanks guys.

              Bob: OK, yours is straightforward, but what is 'x' defined as?

              George
              (OOP is clear in concept, murky in the details)
              The interface of the class you want to use.

              Comment

              Working...
              X