Possible Ge.Application bug in Mechanical 2005

Discussion in 'AutoCAD' started by dhaverstick, Oct 6, 2004.

  1. dhaverstick

    dhaverstick Guest

    Can anyone duplicate this behavior in Autocad Mechanical 2005 VBA/VB?

    Sub test()
    Dim GEAPP As GeApplication
    Dim Point1 As GePoint
    Dim Point2 As GePoint
    Dim Var1 As Double

    Set GEAPP = ThisDrawing.Application.GetInterfaceObject("Ge.Application")
    Set Point1 = GEAPP.Point(0, 0, 0)
    Set Point2 = Point1
    Point2.X = 1: Point2.Y = 3
    Var1 = Point1.X 'Point1.X value takes on the value of Point2.X - This should not happen
    Var1 = Point1.Y 'Point1.Y value takes on the value of Point2.Y - This should not happen
    End Sub

    In my programming experience, setting Point2 = Point1 does not mean the same thing as setting Point1 = Point2. However, in my example, this is what is happening. If you can reproduce this behavior then this DLL has a HUUUUUGE problem.

    Darren
     
    dhaverstick, Oct 6, 2004
    #1
  2. dhaverstick

    Norman Yuan Guest

    If no one can duplicate what you described, than that would be a big
    problem. Yes, your code behaves exactly it should. Here Point1 and Point 2
    are merely two variable that pointing to the same GePoint object created
    with the code GEAPP.Point(0,0,0). What happens in your code is something
    like this:

    Dim Point1 As GePoint
    Dim Point2 As GEPoint

    The declared two VARIABLEs (not object itself) are just used as reference to
    object of GePoint type (class). They sit in memory and will hold memory
    addess of GePoint object as their value, but right now, they hold nothing.

    Set Point1=GEAPP.Point(0,0,0)

    Here, GETAPP.Point(0,0,0) creates an instance of GePoint object and the
    object instance take some memory itself, then Point1 variable takes the
    object instance's memory address as its value. The object instance can only
    be reached through reference varaible. That is, if you want to get to an
    instance of an object, you look at a reference variable, the reference
    variable points to you where the object instance is, 'cause it hold the
    object instance's address.

    Set Poin2=Point1

    Now you make Point2 hold the same address value as Point1. Therefore, you
    can do the same thing to that object instance through either Point1 or
    Point2, 'cause they both refer to the same object instance.

    So often, people confuse object variable and object instance, mistakenly
    thinking Dim A As Something and Dim B As Something make two objects. No they
    don't. They are only object variables ready to point to an object instance.
    On the other hand, object instnace can only be reached through reference
    variable, if no reference pointing to an object instnace, the object
    instance will be destroyed by system.



    same thing as setting Point1 = Point2. However, in my example, this is what
    is happening. If you can reproduce this behavior then this DLL has a
    HUUUUUGE problem.
     
    Norman Yuan, Oct 6, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.