Forum Discussion

alejandroparada's avatar
10 years ago
Solved

How can i send a aliases which is a table to function

i wan to create a function where i receive a table(aliases string) and find some information in the rows but when i tried access to the table, its a variable. please find bellow an example:



main()

{

      findaccount("aliases.form.table");

}



function findaccount(table)

{

     n=table.countRow;

     // methods are not displayed.



     n=alieases.form.table.countRow;

     // its working and i can see all methods.



}
  • Hi alejandro, you are passing a string to the function, it will not be converted to a table so will never have the table members.

     


    What you could try is calling eval() on the string as such:


     


    function findaccount(table)


    {


         var t = eval( table );


         n = t.countRow;


         // hopefully will work


    }


     


    This will hopefully evaluate the alias and return the table object.


     


    For this to work, the string that you pass in must be correct in terms of the object references.


     


    E.g. the string parameter in the call findaccount("aliases.form.table"); in your main() function will fail to eval() as "aliases" should be "Aliases" (note capital A).


     


    Regards,


    Phil Baird


     


    P.S. That is a sweet car you have as you Avatar.

1 Reply

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi alejandro, you are passing a string to the function, it will not be converted to a table so will never have the table members.

     


    What you could try is calling eval() on the string as such:


     


    function findaccount(table)


    {


         var t = eval( table );


         n = t.countRow;


         // hopefully will work


    }


     


    This will hopefully evaluate the alias and return the table object.


     


    For this to work, the string that you pass in must be correct in terms of the object references.


     


    E.g. the string parameter in the call findaccount("aliases.form.table"); in your main() function will fail to eval() as "aliases" should be "Aliases" (note capital A).


     


    Regards,


    Phil Baird


     


    P.S. That is a sweet car you have as you Avatar.