Forum Discussion

DHB's avatar
DHB
Occasional Contributor
14 years ago

ODT Classes: Switching references

Hello,



I am working with ODT classes and my problem is the following limitation: "We would like to note that the objects you create via the ODT project item can
be referred to only by one property, array item or data-group variable at a
time. That is, an object cannot be referred to by several properties, array
items or variables in data groups. For instance, if you need to exchange values
of two properties, you will have to assign an empty value to one of these
properties." (taken from TC help, Working With Custom Objects in Scripts).



To bypass this I wrote the following routine:

procedure toogle_reference(

  var a_ref_source : OleVariant,

  var a_ref_destination : OleVariant);

var

  h_temp : OleVariant;

begin

  h_temp := a_ref_source;

  a_ref_source := NIL;

  a_ref_destination := h_temp;

  h_temp := NIL;

end;



Usage in my case:

  toggle_reference(Self.Testenvironment, Self.Testcases[h_i].Testenvironment);



But this is not working, because "Self" is not a known variable.



I want to use a routine, because I do not want to do unnecessary code copy and write this code (with comment) every time I need to switch references.




  1. Any suggestions how to bypass this situation?

  2. Is there an integrated way to clone objects? (because I do not change the object properties, I only read their values)


(TC Enterprise 7.52.678.7)



Thanks,

Dirk

3 Replies


  • Hi Dirk,





    The topic tells about custom objects assigned to properties of an ODT object. It is impossible to assign an existing ODT object to a property of an object type. You need to remove old objects and create new objects instead of switching references.
  • DHB's avatar
    DHB
    Occasional Contributor
    Hi David,



    I am a little confused about your answer:



    >It is impossible to assign an existing ODT object to a property of an object type.

    I am actually doing this, when not storing the reference toggle in an extra routine.

    h_testenvironment := Self.Testenvironment;

    Self.Testenvironment := NIL;

    Self.Testcases[h_i].Testenvironment  := h_testenvironment;

    h_testenvironment := NIL;

    (and vice versa)



    >You need to remove old objects and create new objects instead of switching references.

    Switching references works! But my posted routine is not working, because of this "Self"-Problem.



    So my two questions are still open:


    1. Any suggestions how to bypass this situation?

    2. Is there an integrated way to clone objects? (because I do not change the object properties, I only read their values)


    If I got something wrong, please explain in more detail, maybe with examples.



    Thanks,

    Dirk

  • Hi Dirk,





    It seems, there is a confusion since I am not sure what exact types of properties and objects you are working with. Nevertheless, the 'Self' problem is caused by a general scripting languages restriction - they do not operate pointers. Unfortunately, I cannot suggest you a way to create a stand-alone routine for swapping ODT objects.





    Also, there is no built-in way to clone an ODT object.