A simple teststand applicatio​n passing object reference to C#

Hi,
 I have a  .NET application written in C# which has a UI with  NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit controls. This UI is invoked by a custom step in TestStand. One of the values, entered by user in the UI is a object reference variable created in a previous step. I need to store the values entered in the UI during the edit mode of the step, into the TestStand Step variables. And during the run mode i use these values to execute the logic in C#. 
The problem is during edit time, the object reference variable, entered in the UI, has no value. It is null. So there is no use storing it at edit time. During the runtime i am trying to retrieve the value of the object reference variable using GetValInterface(...) and GetValIDispatch(..) methods of PropertyObject. But the object returned to C# is of type System.__COMObject wherease in TestStand that object reference is of type .NET.
I don't know how a .NET object reference is converted to COM object when it is returned to .Net function.
Also is there any other method to send this object reference variable's (whose value is '.NET' in previous step itself) value to .NET as a .NET object only so that i can typecast to appropriate type and start using.
Thanks.
Please let me know if anything is not clear.
I have attached the .Net project, .ini file for the custom step and a example sequence file.
Attachments:
CCustomStepObj.zip ‏23 KB

Hello Shivapriya,
The example you've sent doesn't compile. And it without it I'm affraid I do not understand the problem you're describing.
You've given references to libraries that you've not attached with your files.
For the C# I see these are the
IADCore.dll
InstrimentInterfaces.dll
TestStand also seems to want to reach for the assembly named TestSystem.dll.
I can only tell you that I have used successfully in the past the Variables in TestStand to hold .NET object references, and call methods on them and I experienced nothing similar that you describe, but I don't quite follow what is the problem here, as I can't use the example. 
I would appriciate if you cold narrow down the example to 1 dll or something where the problem occurs and than resend it.
Regards,
Maciej 
Message Edited by Mac671 on 09-28-2009 02:59 AM

Similar Messages

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • ExternalInterface: pass object reference across interface - how?

    I want to invoke methods on specific Javascript or
    ActionScript objects through calls across the ExternalInterface
    barrier. I would like to be able to do this either AS -> JS or
    JS -> AS.
    So I would like to pass an object reference across the
    interface. I'm not sure exactly what *is* getting passed (is it the
    serialized value of the object?), but it doesn't seem to work as an
    object reference.
    Here's a notional code sample. I have two symmetric object
    definitions, one in Javascript, one in ActionScript. During
    initialization, one instance of each object will be created and
    given a pointer to the other. Then they should each be able to
    invoke a method on the other to "do stuff".
    //----------[ code ]---------------------------------
    //--- Javascript ---
    class JSobj {
    var _asObj;
    JSobj.prototype.setASObj = function(obj) { _asObj = obj; }
    JSobj.prototype.callASObj = function(foo) {
    callASObjectMethod(_asObj, foo); } // does: _asObj.asMethod(foo);
    JSobj.prototype.jsMethod = function(bar) { /* do stuff */ }
    function callJSObjectMethod(obj, args) { obj.jsMethod(args);
    //--- ActionScript ---
    class ASobj {
    var _jsObj;
    public function set jsObj (obj:Object):void { _jsObj = obj;
    public function callJSObj (foo:Number):void {
    ExternalInterface.call("callJSObjectMethod", _jsObj, foo); } //
    does: _jsObj.jsMethod(foo);
    public function asMethod (bar:Number):void { /* do stuff */
    function callASObjectMethod (obj:Object, args) {
    obj.asMethod(args); }
    ExternalInterface.addCallback("callASObjectMethod",
    callASObjectMethod);
    //----------[ /code ]---------------------------------
    My workaround is to pass a uint as an opaque handle for the
    object, then resolve it when it is passed back. I'd rather pass a
    real reference if possible. Is there a way to pass object
    references between JS and AS?
    Thanks,
    -e-

    It's an object of a class that extends Object. I guess the answer is no then.
    Thanks for your answer

  • Pass object reference from TestStand to C#

    Hi,
    I have created a GUI in .NET which i invoke in TestStand (through a custom step type). User can enter a object reference teststand variable in the UI input expression box. So i need to get the object value in that variable and use it to call some .net functions. To get the values from expression box of UI and put in TestStand step variable i use:
             PropertyObject.SetValInterface("Step.TestStationObj", 0, tsexprTestStationObj.DisplayText.Trim()); To check the value in the step variable if i do:
             MessageBox.Show("TestStation obj after setting:",PropertyObject.GetValInterface("Step.TestStationObj",0).ToString());
    But i do not get any value. Guess it is null. Is this a correct way? My intension is to get the value corresponding to a teststand object reference and pass it to C#. The C# UI control is of type NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit

    Thanks Andy.
    I still get the error when i am trying to pass the object created from C# to Teststand. I have explained what i am trying to do. Kindly requesting your assitance on this issue.
    I have 2 classes in C# (code given below), I am trying to pass the object of "Counter" (c1) class from the "Mainfrm" to teststand. In teststand(counter.seq), I am trying to access the function "GetCount() and SetCount()". I have attached the snapshot of the error that i get from teststand.
    Class Counter
        private int count;
        public int GetCount ()
           return (count);
        public void SetCount(int _count)
           count = _count;
    Class Mainfrm : Form
        public Counter c1;
            private void Mainfrm (object sender, EventArgs e)
                InitializeComponent();
                axApplicationMgr1.Start();
                mEngine = axApplicationMgr1.GetEngine();
                currentFile = axApplicationMgr1.OpenSequenceFile(@"Counter.seq");
                pobj = mEngine.NewPropertyObject(NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Container, false, "", 0);
                pobj.NewSubProperty("Parameters.ObjRef1", NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Reference, false, "", 0);
                pobj.SetValInterface("Parameters.ObjRef1", 0, (object)c1);
                mExecution = mEngine.NewExecution(currentFile, "MainSequence", null, false, 0, pobj, null, null);
    Attachments:
    ErrorFromTestStand.JPG ‏28 KB

  • Find memory leakage when passing Object Reference from Teststand to vi

    I am using Teststand to call labview vi, and pass ThisContext of sequence to vi as object reference, but if I just loop this step and I can find the memory using keep increasing, how can I avoid the memory leakage inside the vi.
    see my vi, it is to post message to UI.
    Solved!
    Go to Solution.

    You should be using a close reference node to close the references you get as a result of an invoke. In the code below you should be closing the references you get from the following:
    AsPropertyObject
    Thread
    Close those two references once you are done with them.
    Also make sure you turned off result collection in your sequence or you will be using up memory continually for the step results.
    Hope this helps,
    -Doug

  • Passing object references to methods

    i got the Foo class a few minutes ago from the other forum, despite passing the object reference to the baz method, it prints "2" and not "3" at the end.
    but the Passer3 code seems to be different, "p" is passed to test() , and the changes to "pass" in the test method prints "silver 7".
    so i'm totally confused about the whole call by reference thing, can anyone explain?
    class Foo {
        public int bar = 0;
        public static void main(String[] args) {
                Foo foo = new Foo();
                foo.bar = 1;
                System.out.println(foo.bar);
                baz(foo);
                // if this was pass by reference the following line would print 3
                // but it doesn't, it prints 2
                System.out.println(foo.bar);
        private static void baz(Foo foo) {
            foo.bar = 2;
            foo = new Foo();
            foo.bar = 3;
    class Passer2 {
         String str;
         int i;
         Passer2(String str, int i) {
         this.str = str;
         this.i = i;
         void test(Passer2 pass) {
         pass.str = "silver";
         pass.i = 7;
    class Passer3 {
         public static void main(String[] args) {
         Passer2 p = new Passer2("gold", 5);
         System.out.println(p.str+" "+p.i);  //prints gold 5
         p.test(p);
         System.out.println(p.str+" "+p.i);   //prints silver 7
    }

    private static void baz(Foo foo) {
    foo.bar = 2;
    foo = new Foo();
    foo.bar = 3;This sets the bar variable in the object reference by
    foo to 2.
    It then creates a new Foo and references it by foo
    (foo is a copy of the passed reference and cannot be
    seen outside the method).
    It sets the bar variable of the newly created Foo to
    3 and then exits the method.
    The method's foo variable now no longer exists and
    now there is no longer any reference to the Foo
    created in the method.thanks, i think i followed what you said.
    so when i pass the object reference to the method, the parameter is a copy of that reference, and it can be pointed to a different object.
    is that correct?

  • Passing object references via methods

    Why is the JFrame object not being created in the following code:
    public class Main {
      public static void main(String[] args) {
        Main main = new Main();
        JFrame frame = null;
        main.createFrame(frame);  // <-- does not create the "frame" object
        frame.pack();
        frame.setVisible(true);
      private void createFrame(JFrame frame) {
        frame = new JFrame("createFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }Thanks.

    These explanations are great; real eye openers.
    OK. This could be a "way out in left field" question. I am just starting out with Java. But I want to ask:
    Objects are stored in the heap?
    Object references and primitives are stored on the stack?
    Adjusting heap size is straight-forward. A larger heap can store more/larger objects. What about stack sizes?
    C:\Dev\java -Xss1024k Main
    I assume this refers to method's stacks. But, what about object scoped, and class scoped, object references?
    public class Main {
      private static List list = new ArrayList(); // class scoped
      private JFrame frame = new JFrame();  // object scoped
      public static void main(String[] args) { ...... }
      private void createFrame() { .... }
    }How is the reference to list and frame stored, with regard to memory management?
    Do objects have stacks?
    Do classes have stacks?
    If not, how are the list and frame references stored (which helps me understand reference scoping).
    Would the overflow of a method stack (ex. via recurssion) also overflow the method's object and the method's class stacks?
    If these questions are stupid, "out of left field", don't matter, etc. Just ignore them.
    But the knowledge could help me avoid future memory related mistakes, and maybe pass a "Java Certified Developer" exam?
    My original question is already answered, so thanks to all.

  • Passing object reference array to a method

    Hi everyone,
    I'm new to the java programming language. I want to create create a array of 50 objects and pass them in to a method in other class.
    Can anyone help me on this problem........................
    Chathu.

    Object[] objectArray = new Object[50];
    objectArray[0] = "Hello World";
    objectArray[1] = new Integer(42);
    myClass.myMethod(objectArray);

  • Pass by reference and String

    public class Test {
        static void method(String str) {
            str = "String Changed";
        public static void main(String[] args) {
            String str = new String("My String");
            System.out.println(str);
            method(str);
            System.out.println(str);
    }The output is
    My String
    My String
    How this is possible when objects are passed by reference ?

    > How this is possible when objects are passed by reference ?
    All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.
    ~

  • Calrification on Pass by reference

    Hi All,
    In java, if we are passing an object to a function actually we are passing the reference. So, if the function is doing any manipulation on the Object reference, it will affect the passing object.
    For example,
    class Ob1
         int i=0;
    public class Ref
         public static void main(String a[])
              Ob1 o=new Ob1();
              System.out.println("Before calling :"+o.i);
              call(o);
              System.out.println("After calling :"+o.i);
         static void call(Ob1 o)
              o.i++;
    Is it possible to get the original value of i(object Ob1) after calling call()?
    Thanks in advance
    +Sha                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    > In java, if we are passing an object to a function
    actually we are[b] passing the reference.
    By value.
    Is it possible to get the original value of i(object
    Ob1) after calling call()?
    Store the original value in a local variable.
    And please note the following:
    All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.

  • Confused about passing by reference and passing by valule

    Hi,
    I am confuse about passing by reference and passing by value. I though objects are always passed by reference. But I find out that its true for java.sql.PreparedStatement but not for java.lang.String. How come when both are objects?
    Thanks

    Hi,
    I am confuse about passing by reference and passing
    by value. I though objects are always passed by
    reference. But I find out that its true for
    java.sql.PreparedStatement but not for
    java.lang.String. How come when both are objects?
    ThanksPass by value implies that the actual parameter is copied and that copy is used as the formal parameter (that is, the method is operating on a copy of what was passed in)
    Pass by reference means that the actual parameter is the formal parameter (that is, the method is operating on the thing which is passed in).
    In Java, you never, ever deal with objects - only references to objects. And Java always, always makes a copy of the actual parameter and uses that as the formal parameter, so Java is always, always pass by value using the standard definition of the term. However, since manipulating an object's state via any reference that refers to that object produces the same effect, changes to the object's state via the copied reference are visible to the calling code, which is what leads some folk to think of java as passing objects by reference, even though a) java doesn't pass objects at all and b) java doesn't do pass by reference. It passes object references by value.
    I've no idea what you're talking about wrt PreparedStatement, but String is immutable, so you can't change its state at all, so maybe that's what's tripping you up?
    Good Luck
    Lee
    PS: I will venture a guess that this is the 3rd reply. Let's see...
    Ok, second. Close enough.
    Yeah, good on yer mlk, At least I beat Jos.
    Message was edited by:
    tsith

  • To pass parameter values to the object reference of action step in sequence file of teststand programatically using C#.

    //Initialize the Engine
                EngineClass myEngine = new EngineClass();
                myEngine.LoadTypePaletteFilesEx(TypeConflictHandlerTypes.ConflictHandler_Prompt, 0);
                Step myStep = myEngine.NewStep(AdapterKeyNames.DotNetAdapterKeyname,StepTypes.StepType_Action);
                myStep.Name = "object";
                DotNetModule dotnetmodule = myStep.Module as DotNetModule;
                dotnetmodule.SetAssembly(DotNetModuleAssemblyLocations.DotNetModule_AssemblyLocation_File,@"C:sequence.dll");
                dotnetmodule.ClassName = "CN";
                dotnetmodule.MemberType = DotNetModuleMemberTypes.DotNetMember_GetProperty;
                dotnetmodule.MemberName = "ISI";  
    mySequence.Locals.NewSubProperty("object", PropertyValueTypes.PropValType_Reference, false, "", 0);        
    Sequence mySequence = myEngine.NewSequence();
                mySequence.Locals.NewSubProperty(varName, PropertyValueTypes.PropValType_Reference, false, String.Empty, 0);
    mySequence.InsertStep(myStep, 0, StepGroups.StepGroup_Main);
                SequenceFile seqFile = myEngine.NewSequenceFile();
                seqFile.InsertSequence(mySequence);
    seqFile.Save("C:\\mySeq.seq");
    I have done this,dynamically creating a sequence file in teststand programatically through c#.
    Problem is
    1.I created an action step and object Reference variable for the step, but i am not able to pass  parameter values to the objectReference 
    2.I am not able to load the sequence in to the main Sequence of the sequence file in the teststand. How can I do these two things.

    Hi,
    have you ever followed on my Links ?!?!?
    If not please jump to this one
    http://forums.ni.com/ni/board/message?board.id=330&thread.id=26880 
    and read the the answer from Mannoch
    starting with this words:
    Anthony -
    Currently, functionality for retrieving the Metadata Token for a class constructor or member is not fully provided in the TestStand .NET Adapter API. The DotNetModule.GetConstructorMetadataToken() and DotNetModule.GetMetadataToken() methods only return the correct Metadata Token when the member/constructor prototypes have already been loaded. Thus, in the case of your code, when you call DotNetModule.GetMetadataToken(), the method is returning -1 because the member prototype for the Step you are referring to has not yet been loaded.
    That means have to do a workaround for your stuff.
    Juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

  • CPP DLL's use pass-by-reference integration with teststand

    I have the detail in the attached Outlook format file.
    Attachments:
    CPP DLL Integration with Teststand.docx ‏120 KB

    If you don't know what a method is, you're going to have a number of problems down the road... A method is a function. It's a member of a class. It sounds like you may need to go through some .NET tutorials to understand the terminology.
    Arrays in .NET are objects and are always passed by reference. That said, you would need to provide the details on the method's signature (i.e., the function prototype). Is the array a System.Array object or a regular old "int[]"? Is the method actually returning an array, or is it operating on the array in place. What is the return datatype of the method?
    Message Edited by smercurio_fc on 08-15-2008 02:26 PM

  • Passing objects by reference in PL/SQL

    Hi,
    I have come across an unexpected problem using object types in PL/SQL that is causing me some grief. I'm from a Java background and am relatively new to Oracle Objects but what I'm trying to do is fairly trivial, I think. The code below illustrates the problem.
    --- cut here ---
    CREATE OR REPLACE TYPE test_obj_t AS OBJECT
    num INTEGER,
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT
    CREATE OR REPLACE TYPE BODY test_obj_t IS
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT IS
    BEGIN
    num := 0;
    RETURN;
    END;
    END;
    CREATE OR REPLACE PACKAGE test_obj_ref AS
    PROCEDURE init(o IN test_obj_t);
    PROCEDURE inc;
    FUNCTION get_num RETURN INTEGER;
    END;
    CREATE OR REPLACE PACKAGE BODY test_obj_ref IS
    obj test_obj_t;
    PROCEDURE init(o IN test_obj_t) IS
    BEGIN
    obj := o;
    END;
    PROCEDURE inc IS
    BEGIN
    obj.num := obj.num + 1;
    END;
    FUNCTION get_num RETURN INTEGER IS
    BEGIN
    RETURN obj.num;
    END;
    END;
    --- cut here ---
    The object type test_obj_t holds a integer and the test_obj_ref package holds a 'reference' to an instance of the object.
    To test the above code I run this PL/SQL block:
    declare
    obj test_obj_t;
    begin
    obj := test_obj_t;
    test_obj_ref.init(obj);
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    end;
    giving the output:
    obj.num=0
    test_obj_ref.get_num=0
    obj.num=0
    test_obj_ref.get_num=1
    obj.num=0
    test_obj_ref.get_num=2
    It appears that the object held by the test_obj_ref package is being incremented as expected, but I would have expected the object declared in the PL/SQL block to be pointing to the same object and so should report the same incremented values.
    I suspect that the object is copied in the call to test_obj_ref.init() so I end up with two object instances, one that is held by the test_obj_ref package and one in the anonymous block. Although, I thought that all IN parameters in PL/SQL are passed by reference and not copied!
    Am I right?
    Is passing objects by reference possible in PL/SQL, if so how?
    I'm using Oracle 10.2.0.3.
    Cheers,
    Andy.

    the object being passed to the test_obj_ref.init+ procedure is passed by reference; however, when you assign it to your package variable obj it is being copied to a new instance. you can pass object instances as parameters to procedures using the +IN OUT [NOCOPY]+ *calling mode, in which case modifications to the attributes of the passed object will be reflected in the calling scope's instance variable.
    oracle's only other notion of an object reference is the +"REF &lt;object-type&gt;"+ datatype, which holds a reference to an object instance stored in an object table or constructed by an object view.
    hope this helps...
    gerard

  • Does Java pass objects by Reference

    The following is my code:
    public static boolean isValid(String tester, Integer intHours, Integer intMinutes)
              int dotPosition = tester.indexOf('.');
              String hours = tester.substring(0, dotPosition);
              String minutes = tester.substring(dotPosition +1, tester.length());
              try {
                        intHours = Integer.valueOf(hours);
                        intMinutes = Integer.valueOf(minutes);
         } catch (NumberFormatException nfe) {
         return false;
         return true;
    What Iam trying to do is pass the Integer Objects by reference so that they retain their values outside of the scope of the function. My teacher told me that objects are passed by reference in Java but (even though the values are being changed within the function they are not retaining their values outside the scope of the function. Was my teacher wrong?

    aden_jones wrote:
    So to get behaviour similar to passing by reference I would need to create my own object and give it a method e.g. MyObject.changeValue(new_value) but I can't do that with Integer objects because I can't change their actual value I can only change the Integer Object that is being pointed at??You cannot achieve behavior that duplicates PBR with Java.
    However, if by "similar to passing by reference" you mean that the method makes a change that the caller can see, then, yes, you need to pass a reference to a mutable object, and change that object's state inside the method.
    void foo(Bar bar) {
      bar.setBaz(123);
    Bar bar = new Bar();
    bar.setBaz(999);
    foo(bar);
    // after foo() completes, the caller now sees that the Bar object's internal state has changed
    // from 999 to 123Note the difference between changing the value of a caller's variable (which can be done with PBR, and cannot be done in Java) and changing the state of the single object pointed to by both the caller's variable and the method's copy of that variable (which can be accomplished in Java, as it does not rely on PBR).

Maybe you are looking for

  • How do you know what Mac Mini version you are getting?

    I heard that as of September 2005, Apple had completly updated there Mac Mini's.. I heard that they put in a 64mb 9200 Graphic Card, and all had Bluetooth and Airport.. But, how would I know that what I am getting is the updated version? Compusa's Ma

  • Dynamic Selection Screen Help

    Hi, I am trying to create a report screen with dynamics call.... I have a Sales Order select-option no interval and no extension then i have few Parameters below such as Customer Name, Part No, Material... Whenever i select a SO, the screen will refr

  • Ale/idoc configuration Guide

    Hi, Hi i am trying to create ale/idoc scenario between my two clients. Can any one tell me steps by steps configuration of that. Regards, Gurprit Bhatia

  • WebLogic test RMI

    Hi, I'm trying to test a call RMI in WebLogic 10.3.6 but an error is generated... String serviceAddress = "rmi://localhost:7001/BeanRemoteService"; Naming.lookup(serviceAddress); java.rmi.ConnectIOException: error during JRMP connection establishment

  • Cant pair BLACKBERRY 9700 desktop manager software with P300

    Hello, Hope someone can help. Im running a Toshiba P300 Bluetooth enabled Laptop. Did have a Nokia N96 which paired up no problem with PC Suite but ive tried everything with this Blackberry and their Software the Desktop Manager and i just cannot get