Multiple variables for same (temporary) table

AKAK Member Posts: 226
edited 2010-12-03 in Navision Financials
Hi,

I've 2 variables which point to the same table, and both have the property "temporary" set. So variable A should store one set of records, variable B another one. If the same record exists in the recordset of A, I can still insert it in B. If a record is modified by using variable A, this doesn't affect the same record stored with variable B. Am I right?

I've too much data to debug it properly in my actual task, but it seems as if action by using variable A are affecting record assigned to B. Is there a known bug in 2.xx?

Thanks!

Comments

  • DenSterDenSter Member Posts: 8,307
    Whenever I get to a question like this, I create a little test form to see what happens. In your case, you could create a form with a button and two temp table variables. I would probably use a master table, because they are easy to work with, so let's use the Item table. In OnPush you insert the same Item into each variable, but with different Description. If they would both point to the same internal temp table you should not be able to INSERT the same Item twice. Then program a message that displays the number and description of both of them and see what happens.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    Whenever I get to a question like this, I create a little test form to see what happens. In your case, you could create a form with a button and two temp table variables. I would probably use a master table, because they are easy to work with, so let's use the Item table. In OnPush you insert the same Item into each variable, but with different Description. If they would both point to the same internal temp table you should not be able to INSERT the same Item twice. Then program a message that displays the number and description of both of them and see what happens.


    You mean something like "if you give a man a fish you feed hi for a day, if you teach him to fish you feed him for life."

    I think What Daniel is saying is extremely important, yet being forgotten by too many developers today. Asking for guidance is one thing, but there are some things you have to do and try and learn from.
    David Singleton
  • AKAK Member Posts: 226
    Thanks, but I already did this (should have mentioned it, sorry). It works like expected. But my code is a bit more complicated, using a recursive function in which the temporary tables are created and modified, which is hard to debug with the old debugger. I kind of hoped someone would say "known problem, this never really worked stable until version 3.xx" or something like that so I could look for a different solution for my task.
    But if it should work I'd like to find my mistake.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    You mean something like "if you give a man a fish you feed hi for a day, if you teach him to fish you feed him for life."
    Shouldn't that be "Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer all day." :-k
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
    AK wrote:
    Thanks, but I already did this (should have mentioned it, sorry). It works like expected. But my code is a bit more complicated
    A change in x variable will not affect the value of y variable. There is no such issue in any version that I know of. If you find that variable y has a value that is supposed to belong to variable x, you need to find where this value gets set, because that is where the problem starts. Probably a case of mixed up variable names.

    What I can imagine is probably happening is that in this massive amount of code, there are two variables that have very similar names. Somewhere down the line some code that applied to one of them was copied to apply to the other, and Ctrl+H was used to do a find/replace. Now you're in debugging mode and you're not sure which variable is supposed to hold what value. I can predict with a fair amount of certainty that the variables are exactly what they are supposed to be according to the code. Good luck finding out where the error is.

    Fun times with the debugger eh :mrgreen:
  • David_SingletonDavid_Singleton Member Posts: 5,479
    You mean something like "if you give a man a fish you feed hi for a day, if you teach him to fish you feed him for life."
    Shouldn't that be "Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer all day." :-k

    :mrgreen:
    David Singleton
  • AKAK Member Posts: 226
    You mean something like "if you give a man a fish you feed hi for a day, if you teach him to fish you feed him for life."
    I think What Daniel is saying is extremely important, yet being forgotten by too many developers today. Asking for guidance is one thing, but there are some things you have to do and try and learn from.

    Well, actually I wasn't asking for fish nor did I expect someone to teach me fishing. I wanted to know if there are sharks in the water, because usually I fish in a different sea...
  • David_SingletonDavid_Singleton Member Posts: 5,479
    AK wrote:
    I kind of hoped someone would say "known problem, this never really worked stable until version 3.xx"

    Temptables had a few issues in the early versions, but by ver. 1.3 they were stable, and by 2.01 (I think that's when they allowed secondary keys) they worked great and without issues.
    David Singleton
  • kinekine Member Posts: 12,562
    There is only one case, when you can use two "variables" on one temporary table. When you define the record variable as array. Each entity in the array will use same instance of temporary table (different "cursors" on same table). But if you are using two variables and both are temporary, they are isolated from each other.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    i hate that old debugger, even if some times it was funny to see it debugging itself...
    sometimes, with small sized databases, i used this approach: backup the database, convert it to newer version, debug the code, restore the database on the old client... :twisted:
    EDIT: ideally you should
    1 backup
    2 create a new db on a newer client
    3 restore the database on the new database you have created at point 2 and debug
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.