Forum Discussion

amvlad's avatar
amvlad
New Contributor
14 years ago

ODT caller

Hi,



Using the following Classes defined in ODT:



Class: App



Members:

App.Member1 of type (MemberClass)

App.Member2 of type (MemberClass)



Class: MemberClass

Method:

MemberClass.Method()



Considering the above ODT is used in scripts like:



App.Member1.Method()

or

App.Member2.Method()



Is there a way to know inside the Method() which was the called member?





Thank you,



Andi

3 Replies

  • amvlad's avatar
    amvlad
    New Contributor
    Hi David,



    Unfortunately i need more than that, at a logical point of view here's what i would want (the following code doesn't work as Jscript/C# script doesn't support direct object compare):





    function Method()

    {

      var MemberName = null;

      for (var i=0; i<This.owner.PropertyCount; i++)

         if (This.owner.Properties(i).Value == This)

             MemberName = This.owner.Properties(i).Name;



      // Do something depending on MemberName

    }



    I think if there would be a way to compare the references of the items in that if, i would get what i need but don't know if there's any way to do that



    Thanks,



    Andi

  • Hi Andi,





    Thank you for the clarification. It is impossible to do what you want to do using the 'This' keyword. Please note that it is impossible to get the name of a variable that stores an instance of an object from a method of this object in any programming languages. So, this behavior is quite expected.





    You need to add a custom identification property to your classes and use it in order to differentiate objects.