Forum Discussion

Oferv's avatar
Oferv
Super Contributor
13 years ago

Call function from another project

this link http://smartbear.com/support/viewarticle/11306/ and the information it holds is a little bit confusing for me. what is says is copy the unit that you have in your other project to your current project (means create a copy of the unit under your project including all the code it holds) and then you'll be able to call the functions under this unit that's located in another project so, why not just copy it and use the function in this copied unit using //USEUNIT?!?!? i just don't get the idea behind it.

can anyone explain please?



Thanks

9 Replies

  • djadhav's avatar
    djadhav
    Regular Contributor

    Oferv, the article actually recommends that you do not have to copy the file to your project, just use 'add an existing item' to add a reference to that unit to your project.

    e.g. I have unit A in C:\TC11Projects\...\ProjectA\UnitA and I want to use that unit in Project B located at C:\TC11Projects\...\ProjectB.

    I would open project B in TC and use the add existing item option as shown below to locate and add a reference to the UnitA in the ProjectB

     

    Step_4 - Add files back.png

     

    Now in whichever script file in project B I want to use a rountine from UnitA, I'll add a "uses, import or USEUNIT clause" at the top.


  • Hi,





    There are two ways of calling a routine from another project:

    1. Without copying, add the reference to the routine and use USEUNIT / uses.

    2. Copy the necessary routines only to a new unit in the project and use the USEUNIT / uses as well.
    • vik33's avatar
      vik33
      Occasional Contributor

      Hi Dmitry_Nikolaev,
      I have tried both the methods to call a function from another project. Call goes fine but script execution fails due to object not found error. How would i make use of the NameMapping objects that belong to Project 2.

      To make it simple:

      ' Unit A has a reference for unit B
      'Unit A is in Project A
      'call is from unit A to --> sub B of unit B

       

      Unit A
      'calling sub B from unit A (below statement)
      unit B.Sub B

      -------------------------------

      'Unit B is in a Project B and has its own Namemapping.
      Unit B

      Sub B
      ' here obj_B is getting used.
      end sub

       

      Here is the issue:
      NameMapping for Project A has something like:
      Aliases.Process_A.obj_Parent.obj_A

       

      NameMapping for Project B has something like:
      Aliases.Process_A.obj_Parent.obj_B

       

      The script tries to find obj_B in the NameMapping for Project A which is what causing it to fail.

      How would i make sure that obj_B should be found in NameMapping of Project B?

       

      Please note that if i execute Sub B from project B on its own (without calling it from Proj A) then it passes without any issues.

      Please help.