How To pass parameters between objects (forms..) Revisited

AdministratorAdministrator Posts: 2,425Member, Moderator, Administrator
edited 2007-09-20 in How Tos section
How To pass parameters between objects (forms, reports, ...)? Revisited

http://www.mibuso.com/howtoinfo.asp?FileID=9

Discuss this How To here.

Comments

  • AnonymousAnonymous Posts: 137Guest
    It`s just what I was looking for since a long time now. One CodeUnit that does all the necessary work for passing Parameters. Thanks.
  • RobikRobik Posts: 9Member
    I wanted to use this to store temporary records, but it loose all rows between code calling (after leaving runing code)

    So it is useful only for simple variable types, or i do something wrong... dont know what
    Robert Polz
  • RobikRobik Posts: 9Member
    Robik wrote:
    I wanted to use this to store temporary records, but it loose all rows between code calling (after leaving runing code)

    So it is useful only for simple variable types, or i do something wrong... dont know what

    :) i did something wrong

    i used

    Function GetRec(VAR Rec Temporary)
    {
    Rec := GlobalRec;
    }

    and hoped both will point to same temp table... after that i was changing only Rec variable...

    if i used GetRec in the same runtime as filling rows, returned rec was still full of temp rows, but in another runing time, all rows lost


    Solution is:

    Function GetRec(VAR Rec Temporary)
    {
    Rec <- INSERTS <- GlobalRec;
    }

    and

    Function SetRec(VAR Rec Temporary)
    {
    GlobalRec <- INSERTS <- Rec;
    }

    not as effective (copying of all rows) but working

    looks like (pointer vs. *pointer problem in C syntax :roll: ) well, there are not var-var (ref-ref) variables to solve it

    if all of this is crap, id like to know it, so please write here better solution or info about whats going on in referenced rec temp variables
    Robert Polz
  • RobikRobik Posts: 9Member
    Later, i tried use of RecordRef

    Function GetRecRef(VAR RecRef)
    {
    RecRef.GETTABLE(GlobalRec);
    }

    It works great, no data copy, and returned RecRef had all rows inside

    but, if u like to attach it to Rec variable with using of
    RecRef.SETTABLE(Rec)

    Rec has no rows, which is really great like many other 'qualities' of Navision =D>
    Robert Polz
  • girish.joshigirish.joshi Posts: 407Member
    One problem that isn't mentioned here is that this solution is vulnerable to concurrency issues.

    For example, if two users open up Form 1, then the values you get a race condition to determine which values actually get calculated when they open up Form 2.

    With the appropriate gymnastics, one can get around this, but its probably not worth the effort, since with Luc's original approach parameters can be passed effectively.
  • sveiverssveivers Posts: 2Member
    How To pass parameters between objects (forms, reports, ...)? Revisited

    http://www.mibuso.com/howtoinfo.asp?FileID=9

    Discuss this How To here.

    I am quite new with Navision and need help for a similar situation. I am running a codeunit, from wich i run a Form. The form asks for som values and calculates some. Then when returning to the CodeUnit I need to use these values set in the form. How do I pass them back?
  • krikikriki Posts: 8,638Member, Moderator
    sveivers wrote:
    How To pass parameters between objects (forms, reports, ...)? Revisited

    http://www.mibuso.com/howtoinfo.asp?FileID=9

    Discuss this How To here.

    I am quite new with Navision and need help for a similar situation. I am running a codeunit, from wich i run a Form. The form asks for som values and calculates some. Then when returning to the CodeUnit I need to use these values set in the form. How do I pass them back?
    You can also use this system. But the saving of parameters must be done in the form and the retrieving in the codeunit.
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • mrQQmrQQ Posts: 239Member
    One problem that isn't mentioned here is that this solution is vulnerable to concurrency issues.

    For example, if two users open up Form 1, then the values you get a race condition to determine which values actually get calculated when they open up Form 2.

    With the appropriate gymnastics, one can get around this, but its probably not worth the effort, since with Luc's original approach parameters can be passed effectively.

    each user has it's own copy. worse, if same user opens form 1 twice.

    even worse is error handling. since there are no transactions on function calls, you can have wrong data stored in codeunit (for example you pass a value to single instance codeunit, then call calculation which should cleanup, but it aborts with error.. and garbage data is left in single instance codeunit).
  • krikikriki Posts: 8,638Member, Moderator
    mrQQ wrote:
    even worse is error handling. since there are no transactions on function calls, you can have wrong data stored in codeunit (for example you pass a value to single instance codeunit, then call calculation which should cleanup, but it aborts with error.. and garbage data is left in single instance codeunit).
    How to avoid this:
    -Save singleinstance variables just BEFORE calling the codeunit that should use them. And in the codeunit that should use them, put them in globals or locals and remove the singleinstance variables BEFORE doing anything else.
    -And if you are in object A and want to send a variable to object C but it has to pass through object B, you have to send from A to B and then from B to C.
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • mrQQmrQQ Posts: 239Member
    kriki wrote:
    mrQQ wrote:
    even worse is error handling. since there are no transactions on function calls, you can have wrong data stored in codeunit (for example you pass a value to single instance codeunit, then call calculation which should cleanup, but it aborts with error.. and garbage data is left in single instance codeunit).
    How to avoid this:
    -Save singleinstance variables just BEFORE calling the codeunit that should use them. And in the codeunit that should use them, put them in globals or locals and remove the singleinstance variables BEFORE doing anything else.
    -And if you are in object A and want to send a variable to object C but it has to pass through object B, you have to send from A to B and then from B to C.

    which kinda beats the whole "have it easy" aspect..
  • DenSterDenSter Posts: 8,120Member
    yeah it does defeat the purpose of having certain values stored for 'global' use if those values have to be retrieved to check their validity each time you need those values.

    I think though that the how-to section is meant just to give you an idea of what is possible. If you are in a situation where it doesn't make sense to use this, then don't use it. There are still situations where it DOES make sense to use this. Just because there are a few cases where it is useless does not make the whole idea useless.
  • krikikriki Posts: 8,638Member, Moderator
    I have created my own system of "more global then global variables" and I use it a lot. Of course I always keep in mind that in case of error, the variables remain dirty. That is the reason I invented the system in my previous post to avoid dirty variables. And for the moment that system works really fine. It gives me the possibility to pass parameters with little programming in stead of a lot of programming.
    Of course, discipline is a must!
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • mrQQmrQQ Posts: 239Member
    agreed:) and i didn't say it was useless, i just told about few problems :)
  • girish.joshigirish.joshi Posts: 407Member
    In response to Robik's post and to keep all of this info about passing variables in one place:

    If you are passing temporary records, as Robik describes, I don't think assignment works. I've always written my own "copy constructor" that copies all of the records from temporary record into a new temporary record variable.
Sign In or Register to comment.