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.
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?
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 No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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).
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 No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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..
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.
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 No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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.
Comments
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
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>
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.
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?
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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).
-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.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
which kinda beats the whole "have it easy" aspect..
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.
RIS Plus, LLC
Of course, discipline is a must!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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.